I have the following model
public class Foo
{
public int Id { get; set; }
public IList<Bar> Bars { get; set; }
}
public class Bar
{
public int Id { get; set; }
}
When I generate the database schema from this using EF Code first it creates the following tables:
Is it possible to change the name of the Foo_Id foreign key using attributes?
EDIT: Here is the version that does what I need:
public class Foo
{
public int Id { get; set; }
[ForeignKey("AssignedToBarId")]
public IList<Bar> Bars { get; set; }
}
public class Bar
{
public int AssignedToBarId { get; set; }
public int Id { get; set; }
}
I think it can be done like below:
Or maybe:
[ForeignKey("AssignedToBarID")]
public IList<Bar> Bars { get; set; }
NOTE: I have not tested neither of them. These are just suggestions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With