相关疑难解决方法(0)

EF:使用延迟加载的必需属性时,验证失败

鉴于这个非常简单的模型:

public class MyContext : BaseContext
{
    public DbSet<Foo> Foos { get; set; }
    public DbSet<Bar> Bars { get; set; }
}

public class Foo
{
    public int Id { get; set; }
    public int Data { get; set; }
    [Required]
    public virtual Bar Bar { get; set; }
}

public class Bar
{
    public int Id { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

以下程序失败:

object id;
using (var context = new MyContext())
{
    var foo = new Foo { Bar = …
Run Code Online (Sandbox Code Playgroud)

entity-framework ef-code-first

69
推荐指数
4
解决办法
1万
查看次数

标签 统计

ef-code-first ×1

entity-framework ×1