Skip to content

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

Description

@fanxinshun

在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;

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions