many-to-many

How to define Many-to-Many relationship through Fluent API Entity Framework?

无人久伴 提交于 2019-11-27 17:18:29
Below is my model: public class TMUrl { //many other properties //only property with type Keyword public List<Keyword> Keywords{get;set;} } public class Keyword { //many other properties //only property with type TMUrl public List<TMUrl> Urls{get;set;} } So clearly, both the entities have many-to-many relationship. I chose fluent api to tell the entity-framework about this relationship i.e. modelBuilder.Entity<TMUrl> .HasMany(s => s.Keywords) .WithMany(s => s.URLs).Map(s => { s.MapLeftKey("KeywordId"); s.MapRightKey("UrlId"); s.ToTable("KeywordUrlMapping"); }); but when I do url.Keywords.Add

Generic many-to-many relationships

Deadly 提交于 2019-11-27 17:06:40
I'm trying to create a messaging system where a message's sender and recipients can be generic entities. This seems fine for the sender, where there is only object to reference (GenericForeignKey) but I can't figure out how to go about this for the recipients (GenericManyToManyKey ??) Below is a simplified example. PersonClient and CompanyClient inherit attributes from Client but have their own specific details. The last line is the sticking point. How do you allow message recipients to be a set of CompanyClients and PersonClients class Client(models.Model): city = models.CharField(max_length

Hibernate many to many - fetch method eager vs lazy

那年仲夏 提交于 2019-11-27 16:38:41
问题 New to Hibernate. I have User Group many to many relation. Three tables : User , Group and UserGroup mapping table. Entities: @Entity @Table(name = "user") public class User { @Id @Column (name = "username") private String userName; @Column (name = "password", nullable = false) private String password; @ManyToMany(cascade = {CascadeType.ALL}, fetch = FetchType.EAGER) @JoinTable(name="usergroup", joinColumns={@JoinColumn(name="username")}, inverseJoinColumns={@JoinColumn(name="groupname")})

NHibernate 3.2 many to many mapping by code

对着背影说爱祢 提交于 2019-11-27 16:23:43
问题 I'm trying to learn NHibernate 3.2 built-in mapping by code api ( NOT FluentNHibernate, nor xml). Can you help me to map a many-to-many relationship between these entities please? public class Post { public virtual Id { get; set; } public IList<Tag> Tags { get; set; } } public class Tag { public virtual Id { get; set; } public IList<Post> Posts { get; set; } } My primary key strategy is: Id( t => t.Id, t => { t.Generator(Generators.HighLow, g => g.Params(new { max_low = 100 })); t.Column

Java many to many association map

最后都变了- 提交于 2019-11-27 16:18:04
问题 I have two classes, ClassA and ClassB , as well as a "many to many" AssociationClass . I want a structure that holds the associations between A and B so that I can find the counterpart for each instance of A or B. I thought of using a Hashmap, with pair keys: Hasmap<Pair<ClassA, ClassB>, AssociationClass> associations; This way, I can add and remove an association between two instances of ClassA and ClassB , and I can query a relation for two given instances. However, I miss the feature of

Removing many to many entity Framework

南楼画角 提交于 2019-11-27 15:44:33
问题 There is a many to many relationship between Artist and ArtistType . I can easily add artist ArtistType like below foreach (var artistType in this._db.ArtistTypes .Where(artistType => vm.SelectedIds.Contains(artistType.ArtistTypeID))) { artist.ArtistTypes.Add(artistType); } _db.ArtistDetails.Add(artist); _db.SaveChanges(); This goes and updates the many to many association table with correct mapping. But when I try to remove any item from table I do not get any error but it does not remove it

Django - Cascade deletion in ManyToManyRelation

拟墨画扇 提交于 2019-11-27 15:01:29
Using the following related models (one blog entry can have multiple revisions): class BlogEntryRevision(models.Model): revisionNumber = models.IntegerField() title = models.CharField(max_length = 120) text = models.TextField() [...] class BlogEntry(models.Model): revisions = models.ManyToManyField(BlogEntryRevision) [...] How can I tell Django to delete all related BlogEntryRevision s when the corresponding BlogEntry is deleted? The default seems to be to keep objects in a many-to-many relation if an object of the "other" side is deleted. Any way to do this - preferably without overriding

Entity Framework Code First Many to Many Setup For Existing Tables

放肆的年华 提交于 2019-11-27 14:43:35
I have the following tables Essence , EssenseSet , and Essense2EssenceSet Essense2EssenceSet is the linking table that creates the M:M relationship. I've been unable to get the M:M relationship working though in EF code first though. Here's my code: [Table("Essence", Schema = "Com")] public class Essence { public int EssenceID { get; set; } public string Name { get; set; } public int EssenceTypeID { get; set; } public string DescLong { get; set; } public string DescShort { get; set; } public virtual ICollection<EssenceSet> EssenceSets { get; set; } public virtual EssenceType EssenceType { get;

Query on a many-to-many relationship using Doctrine with Symfony2

你说的曾经没有我的故事 提交于 2019-11-27 14:41:14
I'm triyng to understand how the many to many relationship works with Doctrine and Symfony2. I've recreated the example shown in the official documentation (goo.gl/GYcVE0) and i have two Entity Classes: User and Group as you can see below. <?php /** @Entity **/ class User { // ... /** * @ManyToMany(targetEntity="Group", inversedBy="users") * @JoinTable(name="users_groups") **/ private $groups; public function __construct() { $this->groups = new \Doctrine\Common\Collections\ArrayCollection(); } // ... } /** @Entity **/ class Group { // ... /** * @ManyToMany(targetEntity="User", mappedBy="groups

Deleting record in many-to-many table

痴心易碎 提交于 2019-11-27 14:39:15
问题 I'm following the security chapter of the Symfony 2 book. There's is an example with a table USERS and GROUPS . There is a many-to-many relationship between USERS and GROUPS , which creates in the database a table called USERGROUPS . What I want is to delete a record from USERGROUPS , for example: DELETE from USERGROUPS WHERE user_id = 1 and group_id = 1 I don't know how to do this since I don't have an USERGROUPS.php table file. Using DQL, for example, I want to be able to do this: $em =