EF4.1 Code First, Navigation Property across multiple mapping joins
In SQL, I have a 1:1 relationship defined between 2 tables which are linked by 2 mapping tables, four in total. I have no influence on the database schema.
I'd like to reflect this in my Code First model so that I can say Foo.Bar and Bar.Foo rather than Foo.Mapping1.Mapping2.Bar (or similar). Is this possible using the Fluent API? I know you can specify a many to many relationship using the designer which results in Foo.Bars and Bar.Foos so hopef开发者_高级运维ully this is possible.
I don't know that you can map it with Fluent API but I know you can create an extension class and create an extension to handle the mapping like so:
public static class FooExtension
{
public static Bar Bar(this Foo)
{
var bar = Foo.Mapping1.Mapping2.Bar;
return bar;
}
}
Then you would call the extension method
var foosBar = Foo.Bar()
精彩评论