many-to-many

LINQ to entities - Building where clauses to test collections within a many to many relationship

大憨熊 提交于 2019-11-26 15:26:32
问题 So, I am using the Linq entity framework. I have 2 entities: Content and Tag . They are in a many-to-many relationship with one another. Content can have many Tags and Tag can have many Contents . So I am trying to write a query to select all contents where any tags names are equal to blah The entities both have a collection of the other entity as a property(but no IDs). This is where I am struggling. I do have a custom expression for Contains (so, whoever may help me, you can assume that I

How to manually load related entities in a N:N relationship?

点点圈 提交于 2019-11-26 14:41:26
问题 I am using EF5 and when the the relationship is 1:N, if I want to load related entities I do the following: With T-SQL I load from database the main entities with a T-SQL like that: select * from MainEntities where ... with T-SQL I load the related entities select * from RelatedEntities where IDMainEntity IN (---) At this point EF populate the property navigation of the main entities with the related entities. Also, in the local property of the type of each entity in the dbContext I have all

How to persist @ManyToMany relation - duplicate entry or detached entity

若如初见. 提交于 2019-11-26 13:45:42
问题 I want to persist my entity with ManyToMany relation. But i have some problem during persisting process. My entities : @Entity @Table(name = "USER") public class User implements Serializable { private static final long serialVersionUID = 1L; @Id @Column(name = "ID") @GeneratedValue(strategy = GenerationType.IDENTITY) Long userId; @Column(name = "NAME", unique = true, nullable = false) String userName; @Column(name = "FORNAME") String userForname; @Column(name = "EMAIL") String userEmail;

How to do many-to-many Django query to find book with 2 given authors?

你。 提交于 2019-11-26 13:08:00
问题 I have a query that requires to filter exactly 2 authors with the ID Theoretically, Book.objects.filter(author__id=1, author__id=2). which is not possible. How can I solve this problem? Cheers, Mickey 回答1: Not intuitive at first but the answer is right in front of us. Book.objects.filter(author__id=1).filter(author__id=2) If you want an exact match, you could potentially further filter this result by those items that only have exactly 2 authors. Book.objects.annotate(count=Count('author'))

How to create a many-to-many mapping in Entity Framework?

倖福魔咒の 提交于 2019-11-26 12:53:25
Here is the case, I have 2 entities, such as Contract、Media。 public class Media : Entity { public string Name {get; set;} public bool Enabled *//other properties can be ignored..* } public class Contract : Entity { public string Code {get; set;} *//other properties can be ignored..* } Contract has many Medias, it seems that they are many to many. But!! at ef code first, i need 3 more fields in the ContractMedia table(ef auto generated). such as StartDate,EndDate and Price. these could not be added in Media entity. How to map at this case?? Tomas If you want to create many to many relationship

how to have relations many to many in redis

痴心易碎 提交于 2019-11-26 12:06:30
问题 in an relational database, i have an user table, an category table and an user-category table which do many to many relationship. What\'s the better form of have this structure in redis? 回答1: With Redis, relationships are typically represented by sets. A set can be used to represent a one-way relationship, so you need one set per object to represent a many-to-many relationship. It is pretty useless to try to compare a relational database model to Redis data structures. With Redis, everything

Many to Many Relationships not saving

两盒软妹~` 提交于 2019-11-26 12:04:39
问题 I have two entities with a fairly standard Many to Many relationship that I created in EF 5 Code First. These are Service and ServiceItem. The Service entity contains a collection of ServiceItems and the ServiceItem contains a collection of Services. I can create, change and save data to either of the entities basic properties with no problems. When I try to add a ServiceItem to a Service or a Service to a ServiceItem it seems to work, but nothing is saved. I have verified that all the proper

SQLAlchemy ManyToMany secondary table with additional fields

a 夏天 提交于 2019-11-26 11:55:59
问题 I have 3 tables: User, Community, community_members (for relationship many2many of users and community). I create this tables using Flask-SQLAlchemy: community_members = db.Table(\'community_members\', db.Column(\'user_id\', db.Integer, db.ForeignKey(\'user.id\')), db.Column(\'community_id\', db.Integer, db.ForeignKey(\'community.id\')), ) class Community(db.Model): __tablename__ = \'community\' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100), nullable=False,

How to organise a many to many relationship in MongoDB

自闭症网瘾萝莉.ら 提交于 2019-11-26 10:30:48
问题 I have two tables/collections; Users and Groups. A user can be a member of any number of groups and a user can also be an owner of any number of groups. In a relational database I\'d probably have a third table called UserGroups with a UserID column, a GroupID column and an IsOwner column. I\'m using MongoDB and I\'m sure there is a different approach for this kind of relationship in a document database. Should I embed the list of groups and groups-as-owner inside the Users table as two

NHibernate - Many to Many Query using Junction/Joiner Table

拜拜、爱过 提交于 2019-11-26 10:02:57
问题 I\'ve found very similar questions here but none that match exactly what I\'m looking for. The two closest threads I\'ve found are (yes, they are different threads): NHibernate many-to-many criteria (1) NHibernate many-to-many criteria (2) However, I think both of those are using direct Many-to-Many relationships. I am actually simulating the Many-to-Many relationship by having two One-to-Many relationships with a junction table, which is pretty standard practice. Here are my NHibernate