Entity Framework DB First: Convert Associative Table to Navigation Properties -
i using entity framework database first, replicate following behavior code first paradigm:
in entity framework code first, can along these lines:
public class thing { public int id { get; set; } icollection<stuff> stuffs { get; set; } } public class stuff { public int id { get; set; } icollection<thing> things { get; set; } }
and database generate , associative table represent many many relationship.
i'm using database first legacy database. pulled in entities , included associative table representing many-to-many relationship between 2 of our tables.
since associative table included entity, navigation properties such:
public class thing { public int id { get; set; } public icollection<thingstuff> thingstuffs { get; set; } } public class thingstuff { public int thingid { get; set; } public int stuffid { get; set; } icollection<thing> things { get; set; } icollection<stuff> stuffs { get; set; } } public class stuff { public int id { get; set; } public icollection<thingstuff> thingstuffs { get; set; } }
so navigate, have to:
var stuff = thing.thingstuffs.select(ts => ts.stuff);
instead of:
var stuff = thing.stuffs;
so question is:
is there way drop entity representing association (thingstuff) , tell entityframework existing table create many-to-many navigation properties?
wouldn't better if map composite keys, stated in fluent api documentation? http://msdn.microsoft.com/en-us/data/jj591617.aspx
Comments
Post a Comment