Coldairarrow / EFCore.Sharding

Database Sharding For EFCore
Apache License 2.0
694 stars 144 forks source link

.Net8版本,Db.DeleteAsync<T>(keys) 删除对象报错:Cannot create a DbSet for 'object' because this type is not included in the model for the context #146

Open fanxinshun opened 4 months ago

fanxinshun commented 4 months ago

在DefaultDbAccessor类中,根据主键批量删除方法,GetDeleteList返回的是object集合导致报错,应该返回T泛型集合

以下未经测试 private List GetDeleteList(List keys) { var theProperty = GetKeyPropertys(typeof(T)).FirstOrDefault(); if (theProperty == null) throw new Exception("该实体没有主键标识!请使用[Key]标识主键!");

List<T> deleteList = new List<T>();
keys.ForEach(aKey =>
{
    T newData = Activator.CreateInstance<T>();
    var value = Convert.ChangeType(aKey, theProperty.PropertyType);
    theProperty.SetValue(newData, value);
    deleteList.Add(newData);
});

return deleteList;

}

fanxinshun commented 4 months ago

另外 return await UpdateAsync(list, tracking); 是不是应该改为return await UpdateAsync T (list, tracking);