c# - How to use Many-to-Many relationship in Model First Asp.net MVC? -


i'm new mvc, , confusing me long time seems few questions discuss this.

i'm using model first creating database in asp.net mvc.
if want member relationship between user , project ,
means user has joined project.
, member relationship should have additional attributes contribution , joindate.

i created model this. (sorry chinese)

enter image description here

both user , project have navigation attribute member.

but main problem is, don't know how use it.

if don't need contribution , joindate attributes, map user , project relationship (again, sorry):

enter image description here

and work intuitively maybe

user.projects.add(project); 

now have additional attributes in relationship, don't know how work in way. it's not intuitive.

// user join project. member member = new member(user,project);  // create relationship manually member.contribution = 500; user.members.add(member); 

as return user list , projects each user owns.

var userset = user in db.userset               select new               {                   id = user.id,                   name = user.name,                   projectlist = user.member.select(m => new                   {                       id = m.project.id,                       name = m.project.name                   })               };  return json(userset, jsonrequestbehavior.allowget); 

is there way improve this? please share idea. (thanks patience.)

we faced same problem wanted save signature of every person participates test. did little workaround (sorry bad design created in paint match needs):

er-diagram

even there many-to-many connections every "member" have 1 user , 1 project per entry. access them member.users.first().dosomething();. know not cleanest way , database architect wants kill me if sees works , don't have create entries manually.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -