0

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

                });
  • Which line exactly shows that error? – canton7 Aug 15 '23 at 08:16
  • when I try to cast my join to list (.tolist()). my join line work if i replace it by .AsEnumerable() – MohamadReza Alamdar Aug 15 '23 at 08:50
  • What is `NotMa`? Are you sure it should not be `var NotMa`? I can't spot anything obviously wrong with your query. But if you try to assign the result to some property where it needs a constant value you will indeed get this error. So I would suggest showing the surrounding code. – JonasH Aug 15 '23 at 09:19
  • the NotMa is a var, but in the first join it is var too. i edited my Question for showing more detail. thanks for response. @jonasH – MohamadReza Alamdar Aug 15 '23 at 10:10

0 Answers0