Query data after scaffolding the existing database. Error: The navigation '' cannot be added because it targets the keyless entity type
Query data after scaffolding the existing database. Error: The navigation '' cannot be added because it targets the keyless entity type
我的问题如标题所述。我正在使用 EF 核心来构建现有数据库。它会自动生成所有 table class 文件和 DbContext
class。然后我尝试用 Id = 4341
查询 Offer
table。但是我总是得到这个错误。
The navigation '' cannot be added because it targets the keyless entity type
之前看到有人问过这个问题,但是没有给出明确的解决方案。
这是我查询数据库的方式:
using (var context = new Vmob_xbg178_CoreContext())
{
var offer4341 = context.Offer.Where(s => s.Id == 4341);
}
[
问题是您数据库中的 MessageKeyTag table 没有主键。 EF 假定每个实体都有密钥。否则 table 将被视为视图。
请为您的无钥匙添加一个主键table然后重新生成代码...
我的问题如标题所述。我正在使用 EF 核心来构建现有数据库。它会自动生成所有 table class 文件和 DbContext
class。然后我尝试用 Id = 4341
查询 Offer
table。但是我总是得到这个错误。
The navigation '' cannot be added because it targets the keyless entity type
之前看到有人问过这个问题,但是没有给出明确的解决方案。
这是我查询数据库的方式:
using (var context = new Vmob_xbg178_CoreContext())
{
var offer4341 = context.Offer.Where(s => s.Id == 4341);
}
[
问题是您数据库中的 MessageKeyTag table 没有主键。 EF 假定每个实体都有密钥。否则 table 将被视为视图。
请为您的无钥匙添加一个主键table然后重新生成代码...