使用scaffold-dbcontext添加实体后,对象名称无效

时间:2019-05-24 23:13:52

标签: c# entity-framework .net-core

.net内核刚起步,我只是使用

将数据库表导入到我的项目中
Scaffold-DbContext -tables que.optionalanswer

该实体已成功创建,并将其添加到上下文类中。

然后我尝试访问新添加的实体,并且当该代码运行时,它因以下错误而崩溃:

{
 "IsSuccessStatus": false,
 "ErrorMessages": [
   "Invalid object name 'OptionalAnswer'.",
   "Unknown error, please contact the system admin.RequestId:0HLN0JGS1TMR4:0000000C"
 ]
}

然后堆栈跟踪将我引向EF查询

var result = (from l in _db.Leads
      join ias in _db.ItnanswerSet on l.LeadId equals ias.LeadId
      join a in _db.Answer on ias.AnswerSetId equals a.AnswerSetId
      join oa in _db.OptionalAnswer on a.PossibleAnswerId equals oa.OptionalAnswerId into optans
      from oa in optans.DefaultIfEmpty()
      join q in _db.Question on a.QuestionId equals q.QuestionId
      where (l.LeadId == leadId)

我得到了智能,并且实体在我的项目中,所以有什么想法会失败吗?

编辑:对于遇到此问题的人,对我来说,我将实体添加到上下文中,如下所示:

public virtual DbSet<OptionalAnswer> OptionalAnswer { get; set; }

但是我从未添加过模型构建器定义:

modelBuilder.Entity<OptionalAnswer>(entity =>
    //snip

0 个答案:

没有答案