【发布时间】:2020-04-17 10:13:11
【问题描述】:
我在 Entity Framework Core 3.1 中有项目。当我像这样使用延迟加载时:
services.AddDbContext<IQContext>(options => options.UseLazyLoadingProxies().UseSqlServer(...)
我称之为:
public async Task<Guid> UpdateAsync(object entity ...)
{
...
Type entityType = entity.GetType();
string primaryKeyName = _dbContext.Model.FindEntityType(entityType).FindPrimaryKey().Properties.Select(x => x.Name).Single();
}
我收到了这个错误:
System.NullReferenceException: 'Object reference not set to an instance of an object.'
Microsoft.EntityFrameworkCore.ModelExtensions.FindEntityType(...) returned null.
但是当我删除 UseLazyLoadingProxies() 时,一切正常。
有什么想法可能是错误的或如何解决?
【问题讨论】:
标签: c# entity-framework asp.net-core .net-core entity-framework-core