鉴于这个非常简单的模型:
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)