many-to-many

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

做~自己de王妃 提交于 2019-11-27 09:19:55
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 the entities of each type. However, if i do the same with a N:N relationship, I don't have the entity

ASP.NET MVC Many to Many relationship, using “My Own” table

Deadly 提交于 2019-11-27 08:06:13
问题 I am fairly new to using Code First approach with entity framework and I know that I you have a many to many relationship like the entities below, the EF will create the intermediary table automatically: class Post { ... public virtual ICollection<Category> Categories {get; set;} ... } class Category { ... public virtual ICollection<Post> Posts {get; set;} ... } However, if in the intermediary table I need to have extra data fields, one possible way (which I currently like, maybe because I am

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

怎甘沉沦 提交于 2019-11-27 07:28:58
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 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')).filter(author__id=1)\ .filter(author__id=13).filter(count=2) If you want exact matches dynamically, how about

Query a ManyToMany relation and display the good result in Symfony with Doctrine

天大地大妈咪最大 提交于 2019-11-27 07:15:30
问题 in order to know how it really works, there is an unanswered question from Stack website, and notice that I have the similar problem. In my SQl database , I have two tables: Adverts and Categories Indeed, the Adverts table can contain MANY Categories , and of course a Category can be in many Adverts . So I have a ManyToMany relation between the two tables. in SQL, Doctrine creates me a pivot table named adverts_categories. So far there are no problems , everything is theoretically correct. So

Django admin - How can I add the green plus sign for Many-to-many Field in custom admin form

社会主义新天地 提交于 2019-11-27 07:10:06
问题 The green plus sign button for adding new instances in the admin form disappears for my MultiSelect field (photos) when I define it in my form. Ie, removing the line with the definition (photos = ...) makes the plus sign appear. However, in order to use a custom Field/Widget I need to figure this out. class GalleryForm(ModelForm): photos = ModelMultipleChoiceField(queryset=Photo.objects.all(), label="Photos") def __init__(self, *args, **kwargs): super(GalleryForm, self).__init__(*args, *

Many-to-many relations in Breeze

核能气质少年 提交于 2019-11-27 06:49:37
问题 i am defining some of my models atm using EF5 Code First. I have these three sample classes with a many-to-many relationship: public class Team { [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Team_Id { get; set; } [MaxLength(150)] public string TeamName { get; set; } public virtual ICollection<User> Users { get; set; } [public virtual ICollection<Role> Roles { get; set; } // 1 [Timestamp] public byte[] TimeStamp { get; set; } } public class User { [Key,

how to have relations many to many in redis

孤街醉人 提交于 2019-11-27 06:46:09
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? 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 is stored in a denormalized way. Example: # Here are my categories > hmset category:1 name cinema ... more

Unable to create a constant value of type (type) Only primitive types ('such as Int32, String, and Guid') are supported in this context

拟墨画扇 提交于 2019-11-27 06:44:14
问题 I've read ALL of: Unable to create a constant value of type 'System.Object' in Entity Framework Entity Framework - "Unable to create a constant value of type 'Closure type'..." error Entity Framework - Union causes "Unable to create a constant value of type.." Only primitive types ('such as Int32, String, and Guid') are supported in this context and searched a bit more, but still no solution. I've seen that this happens on EF 3.5 and in 4.0 the Contains method should be supported, but I'm in

Many to Many Relationships not saving

江枫思渺然 提交于 2019-11-27 06:34:38
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 database tables are created, including a ServiceItemService table with the cross keys. The database

Proper way to update bidirectional Many to Many relationship symfony2-doctrine

元气小坏坏 提交于 2019-11-27 06:18:28
问题 I did some research, and after reading this and this (and all the related questions) I still can't figure which is the proper way to update a many to many relationship in Symonfy 2 Doctrine. It feels that there should be a very simple way of doing it that I still haven't found. I have this 2 entities: class student_main { /** * @ORM\ManyToMany(targetEntity="support_log", inversedBy="student_main") * @ORM\JoinTable(name="support_log_student") **/ private $support_log; and class support_log { /