EF - WithOptional - Left Outer Join?

c# entity-framework entity-framework-6

Accepted Answer

For one-to-one FK connection, this is the expected behaviour and cannot be prevented. What EF does is keep track of a secret (shadow) attribute likeint? BarId as theFoo entity.

The sole means of eliminatingLEFT OUTER JOIN If you have bidirectional navigation capabilities and is able to change theBar essentially deleting the default EF one-to-one model from the database model (table) and using Association for Shared Primary Keys insteadMap the fluent configuration call

HasRequired(x => x.Foo)
    .WithOptional(x => x.Bar);

This model'sBar table won't includeFooId Instead of the FK column, use the PK columnId will serve as FK referencing and no longer be identity.Foo table.

This enables EF to disregard upholding aBarId in Foo as it is aware of any relatedBar so that it would be withId equal toFoo.Id .

You are stuck if you can't alter the database design; you may either put up withLEFT OUTER JOIN S, or give up theFoo.Bar setup the relationship as unidirectional one-to-many using the navigation attribute, as you previously suggested.

4
4/7/2017 3:05:54 PM






Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow