0
使用VS 2015,MVC 6 RC1和EF 7 RC1我嘗試使用其單個角色名稱獲取所有用戶的列表。在MVC 6中使用單個角色的用戶列表左側加入
我嘗試過所有關於StackOverflow的建議,但都沒有成功。
我在尋找的SQL是:
SELECT [User].[Email], [Role].[Name]
FROM [User]
LEFT JOIN [UserRoles] ON [User].[Id] = [UserRoles].[UserId]
LEFT JOIN[Role] ON [UserRoles].[RoleId] = [Role].[Id]
我已經寫了下面的和LinqPad(正常工作)測試,並且應該在我的項目工作過,但有錯誤出現:
var q1 = (from user in _context.Users
join ur in _context.UserRoles on user.Id equals ur.UserId into grp1
from fgrp1 in grp1.DefaultIfEmpty()
join r in _context.Roles on fgrp1.RoleId equals r.Id into grp2
from fgrp2 in grp2.DefaultIfEmpty()
select new { UserEmail = user.Email, UserRoleName = fgrp2.Name }).ToList();
和錯誤消息是:
An unhandled exception occurred while processing the request.
InvalidOperationException: Sequence contains no elements
System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
我不知道這有什麼差別,但我有CR eated我自己的角色實體:
public class ExtranetRole : IdentityRole<int> { }
和我自己的用戶實體:
public class ExtranetUser : IdentityUser<int> { }
任何幫助/建議大加讚賞。
感謝它看起來像它是一個左連接的錯誤。我期待着在RC1上工作的基本要素。 – GeoDev