EF: Validation failing on update when using lazy-loaded, required properties

后端 未结 8 2048
栀梦
栀梦 2020-12-04 15:03

Given this extremely simple model:

public class MyContext : BaseContext
{
    public DbSet Foos { get; set; }
    public DbSet Bars { g         


        
8条回答
  •  不知归路
    2020-12-04 15:50

    I know it's a bit late... However, ill post this here. Since i too got horribly annoyed with this. Just tell EF to Include the required field.

    Notice the SMALL change

    using (var context = new MyContext())
    {
        var foo = context.Foos.Include("Bar").Find(id);
        foo.Data = 2;
        context.SaveChanges(); //Crash here
    }
    

提交回复
热议问题