2010-11-24 292 views
0

我有2個表ROL和用戶 與ID用戶和IdRol 公開名單SeeRolFromXUser的rolUsers表(INT ID用戶)// { LINQ與許多實體許多relatioship

 List<string> lisrRP = new List<string>(); 
     var query = from u in contextoBD.Users 
        where u.IdUsers== Iduser 
        select u.Roles;//i had to do that but that returns an entity collection i´ dont know haw to get the rol from an x user 
     foreach (var r in query) 
     { 
      lisrRP.Add(r.ToString()); 
     } 

     return lisrRP; 

    } 
+0

這看起來並不像一個問題。我不確定你在問什麼? – 2010-11-24 09:45:36

回答

0

我不知道如果這能幫助你,你可以這樣做:

Roles MyUsersRole = (from R in contextoBD.Roles 
       where R.IdUsers== Iduser   
       select R).SingleOrDefault(); 

if (MyUsersRole == null) { 
    return; 
} 

SingleOrDefault()預計一個單一的值,否則它設置默認null

+0

我會試着去看看這個命令是不是另一種方式... – jenny 2010-11-26 06:08:08

0

我做到了這樣,和它的作品

 var query = from u in contextoBD.Usuarios 
        where u.IdUsuario == Idusuario 
        select u; 

     List<Role> b = new List<Role>(); 

     foreach (var r in query) 
     { 
      b.AddRange(r.Roles); 
     } 

     return b;