many-to-many

entity framework 4 many to many update

[亡魂溺海] 提交于 2019-12-03 16:22:03
I have 3 tables - User (Id, Name) Roles (Id, Name) UserRoles (UserId, RoleId) I think they are self explanatory. How do I update an entry (UserId and RoleId) in UserRoles? context.User.Roles gives me the list of roles but how do I update them? Thank you. From your comment: context.User.Roles gives me the list of roles. I can do a for-each and update the Id, but how do I update the corresponding UserId foreach RoleId in that table? First of all, you should NOT update the Id's. Secondly, since you are using EF, you should try to think in terms of objects (or entities), rather than "DB-many-to

EF5 code first with ASP.NET Web API: Update entity with many-to-many relationship

*爱你&永不变心* 提交于 2019-12-03 16:07:57
I'm trying to update a Customer in my database using ASP.NET Web API and Entity Framework 5 code-first, but it's not working. My entities look like this: public class CustomerModel { public int Id { get; set; } public string Name { get; set; } // More fields public ICollection<CustomerTypeModel> CustomerTypes { get; set; } } public class CustomerTypeModel { public int Id { get; set; } public string Type { get; set; } [JsonIgnore] public ICollection<CustomerModel> Customers { get; set; } } Nothing all that special. I've built a web interface where users can add a customer by supplying the name

Many to Many Relationships

回眸只為那壹抹淺笑 提交于 2019-12-03 15:46:51
I'm seeing all sorts of different ways to handle many to many relationships in Yii. However, the examples I'm seeing aren't fully fleshed out and I feel like I'm missing something. For instance, Larry Ullman's tutorial doesn't use the self::MANY_MANY relation - http://www.larryullman.com/2010/08/10/handling-related-models-in-yii-forms/ So as far as adding and retrieving records, whats the standard way for handling Many to Many in the Model, Controller and View? clarification: I suppose Im looking for an example involving 2 tables, related by many-to-many, where I can see not only both models,

Should Many to Many Tables Have a Primary Key?

て烟熏妆下的殇ゞ 提交于 2019-12-03 15:44:20
问题 If I have two objects that have a many-to-many relationship, I would typically model them in my database schema with a many-to-many table to relate the two. But should that many-to-many table (or "join table") have a primary key of its own (integer auto-incremented)? For example, I might have tables A and B, each with an ID, and a table called A_B that has a foreign key tuple of (A_ID, B_ID). But should A_B have a primary key auto-incremented ID column of its own, or not? What are the

Saving Many to Many relationship to database in Symfony2

做~自己de王妃 提交于 2019-12-03 15:16:38
问题 In my Symfony2 project I have two related entities: Users and Favorites. They have a many-to-many relationship. My application works as follows: In my Twig-page I have an few items with a button 'Add to Favorites'. When you click the button my controller saves the item_id in the Favorites column. But then I want to save the user who added the item to his favorites and here my application fails. The User and the favorite exist but the joincolumn between Users and Favorites remains empty. I

What is the best way to represent a many-to-many relationship between records in a single SQL table?

怎甘沉沦 提交于 2019-12-03 14:58:49
I have a SQL table like so: Update: I'm changing the example table as the existing hierarchical nature of the original data (State, Cities, Schools) is overshadowing the fact that a simple relationship is needed between the items. entities id name 1 Apple 2 Orange 3 Banana 4 Carrot 5 Mushroom I want to define two-way relationships between these entities so a user viewing one entity can see a list of all related entities. The relationships are defined by an end user. What is the best way to represent these relationships in the database and subsequently query and update them? One way as I see it

Entity Framework - Linq To Entities - Many-To-Many Query Problems

半城伤御伤魂 提交于 2019-12-03 14:37:49
问题 I am having problems querying many-to-many relationships in Linq To Entities. I am basically trying to replicate this query using Linq: Select * FROM Customer LEFT JOIN CustomerInterest ON Customer.CustomerID = CustomerInterest.CustomerID LEFT JOIN Interest ON CustomerInterest.InterestID = Interest.InterestID WHERE Interest.InterestName = 'Football' I have looked around the net and not really found any suitable examples of how to do this. The closest I have got is: List<Customer> _Customers =

hibernate @ManyToMany bidirectional eager fetching

本秂侑毒 提交于 2019-12-03 14:07:12
I have a question which I think should be pretty common but I can't find an answer. I have 2 objects: Group and User. My classes look something like this: class Group { @ManyToMany(fetch = FetchType.EAGER) List<User> users; } class User { @ManyToMany(fetch = FetchType.EAGER) List<Group> groups; } Now, when I try to get a User from the database it brings all its groups and all groups bring all its users and so on. Finally, I'm getting a stackoverflow exception. How can I solve this issue and still have my bidirectional association and the ability to reach the objects in the lists? Do you get

update pivot table in case of many to many relation laravel4

倾然丶 夕夏残阳落幕 提交于 2019-12-03 13:44:45
I have started working with Laravel4 recently. I am facing some problem while updating pivot table data, in case of many to many relation. The situation is: I have two table: Product , ProductType . The relation between them is Many to many . My Models are class Product extends Eloquent { protected $table = 'products'; protected $primaryKey = 'prd_id'; public function tags() { return $this->belongsToMany('Tag', 'prd_tags', 'prta_prd_id', 'prta_tag_id'); } } class Tag extends Eloquent { protected $table = 'tags'; protected $primaryKey = 'tag_id'; public function products() { return $this-

Symfony2 form widgets for many-to-many relations

放肆的年华 提交于 2019-12-03 13:38:52
In Symfony 1 there was as form widget named admin_double_list. It generated two select fields named Unassociated and Associated. It also generated buttons to add items from one list to another. Is there any easy way to accomplish this in Symfony2? Or maybe some other user friendly way to edit many-to-many relations? In the documentation there are only four widgets for many-to-many relations and none of them are very nice when there are massive amount of relation possibilities to edit. You can easily manage many-to-many relationships with entity form field . For example If User as a many-to