Click here to Skip to main content
15,746,420 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to use many to many relationship in EF database first approach. I am having following table structure in sql

Table 1:- studentMaster 
Table 2:- Subjects

My Model1.edmx and sql table structure pic is here


I know how to perform CRUD operation using Entity Framework using DAtabase First approach but how to perform crud operation when table have many to many relationship . I have also put my question on codeproject previously but no proper help is given
Updated 14-Apr-14 0:27am
Sampath Lokuge 14-Apr-14 4:29am    
What's your EF version 4/5 or 6 ?
[no name] 14-Apr-14 4:41am    

1 solution

ok, assuming that you mean mvc, we have to differencate between server side and client side. server side, the entity framework takes care of that, see[^]
client side - by the way, I am no asp programmer - this seems more like a wcf related question (using a rest service for crud operations). And, yes, it may be a bit tricky, because e.g. a json rest service needs to stick to a certain schema to accomplish that, and, further more the orm/ odm used must be aware to that schema to assemble/ reassemble the json data accordingly and needs to implement some query and routing logic (depening on where the final joins are executed, and/or how the query is passed through the layer). in the best case an atomic query is natively executed on the database and only the requested fields are returned to the client in a paginated manner. maybe the jaydata framework can help you. I think it is able to consume a variety of services (among these are wcf related stuff). so if there is no build in solution in pure wcf, consuming an odata service thith jaydata client side may be your best bet, see[^]

In CRUD applications, you have to deal with complex data types and one-to-one, one-to-many and even many-to-many associations. Without a proper framework and no database programming experience, this can be a hard work and a pain while you want to create the application of your dreams.

With JayData the complexity of the problems are reducing significantly. You can grab the entity context definition with JaySvcUtil utility, which translates between OData metadata and JavaScript context definition. You can start work immediately after this procedure.
Share this answer
[no name] 15-Apr-14 16:14pm    
My question is not related to wcf . I simple want to know how to code for create,update,delete operation on database using EF5,Linq,Many-2-Many relationship between tables like studentmaster and subjects .....Like:- one student can have many subjects and one subject can belong to many students

Plz post link if there is useful post for this..... i am unable to find suitable one

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900