I have to use join for a list of classes (in ram) and one table (in database) like:
List <GSS.Repository.Entities.AccessControl.AppUserRole> UserRoleList = new List<GSS.Repository.Entities.AccessControl.AppUserRole>();
Context.Users.ForEachAsync(x => UserRoleList.AddRange(x.Roles)).Wait();
var notExist = (from Entity in UserRoleList // outer sequence
join Auth in Context.tblApplicationUserRole //inner sequence
on Entity.Id equals Auth.UserRole.Id into joined
from j in joined.DefaultIfEmpty()
where j == null
select new RowAuthNotmatchsModel()
{
CreatedByIp = "local",
DateCreated = DateTime.Now,
DateModified = DateTime.Now,
EntityAutenticateValues = "NotExist",
RowAutenticateID = "",
ENtityID = Entity.Id.ToString(),
TableName = "ApplicationUserRole"
}).ToList();
NotMatches.AddRange(notExist);
everything works fine for above join, but when I use another join I get: Unable to create a constant value of type... Only primitive types or enumeration types are supported in this context. my other join is :
//Erorr Line
var NotMa = (from Auth in Context.tblRowAutenticateApplicationUserRole// outer sequence
join Entity in UserRoleList //inner sequence
on Auth.UserRole.Id equals Entity.Id
where Auth.isDeleted == false
select new RowAuthNotmatchsModel
{ // result selector
CreatedByIp = "local",
DateCreated = DateTime.Now,
EntityAutenticateValues = Auth.EntityAutenticate,
RowAutenticateID = Auth.Id.ToString(),
ENtityID = Entity.Id.ToString(),
TempRowVersionProssMade = Entity.RowVersion,
TableName = "LoginLimits",
Stamp = Auth.Stamp,
}).ToList();//end Erorr Line
NotMa = NotMa.Where(x => HelperCommonFuntion.CretePBKDF2Hash(Convert.ToBase64String(x.TempRowVersionProssMade), Convert.FromBase64String(x.Stamp)).Item1 != x.EntityAutenticateValues).ToList();
NotMatches.AddRange(NotMa);
both my var types are same type
List<RowAuthNotmatchsModel>
due to other posts for this issue like this, I fetch database data and then use the join. and my problem solved. but what I wonder and couldn't understand is why in my first join everything worked well. i think i couldn't understand this error very well.
by the way i solved this join by this :
var NotMa1=Context.tblRowAutenticateApplicationUserRole.Where(x=> !x.isDeleted)
.ToList().Join(
UserRoleList, Auth => Auth.UserRole.Id, Entity => Entity.Id, (Auth, Entity) => new RowAuthNotmatchsModel
{
CreatedByIp = "local",
DateCreated = DateTime.Now,
EntityAutenticateValues = Auth.EntityAutenticate,
RowAutenticateID = Auth.Id.ToString(),
ENtityID = Entity.Id.ToString(),
TempRowVersionProssMade = Entity.RowVersion,
TableName = "ApplicationUserRole",
Stamp = Auth.Stamp
});