Friday 15 February 2013

orm - Entity framework many to many but also a relationship can occur more than once -


I do not know how to define this relationship. I have users and badges, users can collect many badges, they have There may be a badge more than once (just like the Stackwormflow).

How can I define this number interchange order count?

I have tried just being the user.Badj.ed (badge) again, but it does not get inserted into the database.

At this time, the badge is defined (class inside the user) as:

  public virtual icons back & lt; Badges & gt; Badge {receive; Set; }   

Thanks!

You need a relationship invitation eg. UserBadge, then nav properties will have ICllection UserBadges

UserBadge will have a NAV property for users and badges, as well as a PK ID field.

To get a countdown again, you will group the user's UserBadges ICollection by the badge, then calculate each group:

  var badgeCountQuery = in userITIt . Select new g by userbase group uub by ub.Badge {badge = gkk, badgecount = g. Calculation ()};    

No comments:

Post a Comment