1
I have a table of units as below:
public class Unity
{
public int Id {get;set }
public string Name{ get; set; }
}
public class UsersRight
{
public int Id {get;set }
public string Name{ get; set; }
public int Value{ get; set; }
}
Each user can have access to 1 or n units. I’ll have a list of the units' records.
var userRight = new List<UsersRight>;
userRight = _DAL.UserRights(user);
var listUser = new List<Unity>;
foreach (var item in userRight)
{
listUser.add( new Unity(Name = item.Name, Id = item.Value));
}
What is the most efficient way to do this with EF? I am using ASP.NET Identity.
From what I understood you would have to create a link table between User and Unit, because a user has access to several Units and a Unit would be connected to several users, correct ?!
– William Cézar
Your Case seems to me N:N that would have to have a relationship table between them, for example , 2 users have access to the same Unit , but if it is not so the user would have a Icollection of Units, see this link where it shows a relationship 1:N http://www.entityframeworktutorial.net/code-first/configure-one-to-many-relationship-in-code-first.aspx
– William Cézar
Look at this question as well : http://answall.com/questions/22042/related-n-para-n-e-um-para-n-com-codefirst-data-annotations
– William Cézar
In fact each user can have 1 or n drives. And each drive can have multiple users
– b3r3ch1t
So this Relation is N:N, you would need an extra table, making that link, anything I reply explaining how it would be with examples.
– William Cézar
I also need your drifting class
IdentityUser
.– Leonel Sanches da Silva
I will receive the data from the logged in user with the Claims relation.
– b3r3ch1t