entity framework - Mapping same collection with two Navigation Properties -
i have following model
public class locale { public int id { get; set; } public icollection<localization<locale>> localizations { get; set; } } public class localization<t> { public int id { get; set; } public locale locale { get; set; } public string displayname { get; set; } public t entity { get; set; } }
in case, want able localize entity, include localization (ie: places show available languages in users language ).
i have working in nhibernate, need move ef. issue arises when want use fluent api map follows.
modelbuilder.entity<locale>() .hasmany(x => x.localizations) .withrequired(x => x.locale) .map(x => x.mapkey("localeid"));
this works, need map entity itself. doing overrides previous map.
modelbuilder.entity<locale>() .hasmany(x => x.localizations) .withrequired(x => x.entity) .map(x => x.mapkey("entityid"));
doing way throws error on either field (i've tried making sub class of localization called localelocalization, same result).
modelbuilder.entity<localization<locale>>() .hasrequired(x => x.entity) .withmany() .map(x => x.mapkey("lcidlocale"))
the error
the navigation property "entity" not declared property on type localization. verify has not been explicitly excluded model , valid navigation property.
the solution need map 2 collections, 1 representing collection of localizations locale, , 1 representing collection of other locales localized locale.
icollection<localizations> mylocalizations { get; set; } icollection<localizations> localeslocalizedbyme { get; set; }
Comments
Post a Comment