Monday 15 June 2015

c# - Entity Framework 6 two different collections referring same entity -



c# - Entity Framework 6 two different collections referring same entity -

i got next scenario:

users can presidents or managers of communities. when specifying navigation property connect community president , manages, got this:

public class community { ... [foreignkey("president")] public int? presidentid { get; set; } public virtual user president { get; set; } [foreignkey("manager")] public int? managerid { get; set; } public virtual user manager { get; set; } }

but here comes part can't find solution. have 2 collections on users reffering each communities manage, , ones preside:

public class user { ... public virtual icollection<community> managedcommunities { get; set; } public virtual icollection<community> presidedcommunities { get; set; } }

and can't find documentation on how create first 1 point ones user manages , sec ones he's presising. in advance.

as documented in code first info annotations (msdn), can utilize inverseproperty attribute.

[inverseproperty("manager")] public virtual icollection<community> managedcommunities { get; set; } [inverseproperty("president")] public virtual icollection<community> presidedcommunities { get; set; }

c# entity-framework

No comments:

Post a Comment