I'm new to MVC, and this confusing me for a long time but seems few questions discuss about this.
I'm using Model first creating Database in ASP.NET MVC.
If I want a Member relationship between User and Project ,
means which user has joined to which project.
And the member relationship should have additional attributes contribution and joinDate.
I created a model like this. (Sorry for chinese)
Both User and Project have a navigation attribute Member.
But the main problem is, I don't know how to use it.
If I don't need the Contribution and JoinDate attributes, I could easily just map the User and Project relationship like this (again, sorry):
And this could work very intuitively by maybe
user.projects.Add(project);
Now I have the additional attributes in the relationship, I don't know how to work in this way. It's very not intuitive.
// The user join to the project.
Member member = new Member(user,project); // create a relationship manually
member.contribution = 500;
user.members.Add(member);
As well as to return the user list and projects each user owns.
var userSet = from 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 any way to improve this? Please share your idea. (Thanks for patience.)