Entity Framework: The argument to DbIsNullExpression must refer to a primitive or reference type

后端 未结 2 1291
慢半拍i
慢半拍i 2021-01-16 20:07

I\'m trying to use entity to do this:

    SELECT *
    FROM aspnet_Users u LEFT JOIN (SELECT u.UserId, p.Permission, p.MediaId, p.Valid
                              


        
2条回答
  •  不要未来只要你来
    2021-01-16 20:51

    I realize that since in the second query,it still have the left join with aspnet_Users table, it does not need to have u in the 1st query, so I changed it to below, it works now. But still, it will be great to know why the original code and suggested code failed.

        var up = from u in en.aspnet_Users
                         join p in en.Permissions
                             on u.UserId equals p.UserId into pu
                         from p2 in pu.DefaultIfEmpty()
                         where p2.MediaId == this.MediaId && p2.Valid == true
                         select p2;
    
                var ul = from us in en.aspnet_Users
                         join pm in up
                              on us.UserId equals pm.UserId into pm1
                         from pm2 in pm1.DefaultIfEmpty()
                         orderby us.LoweredUserName
                         select new PermissionInfo
                         {
                             Permission = (pm2 == null ? -1 : pm2.Permission1),
                             UserName = us.UserName,
                             UserId = us.UserId,
                             PermissionId = (pm2 == null ? -1 : pm2.PermissionId)
                         };
    
                ret = ul.ToList();
    

提交回复
热议问题