Skip to content Skip to sidebar Skip to footer

Entity Framework - Not Using Linked Table Id In Insert Query

I have 2 tables, Foo and Bar, Foo has a link to a Bar record public class Foo { public int Id { get; set; } public Bar SomeBar{ get; set; } } public class Bar { public

Solution 1:

Try adding ForeignKey attribute in class Foo and remove the nullable Id in Bar

public class Foo
{
    [ForeignKey("Bar")]
    public int Id { get; set; }
    public Bar SomeBar{ get; set; }
}

public class Bar
{
    public int Id { get; set; }
    ...
}

Post a Comment for "Entity Framework - Not Using Linked Table Id In Insert Query"