Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
253 views
in Technique[技术] by (71.8m points)

Check if string does not contain strings of an array of string in C# in query from Entity Framework

I tried to get a special count where I want to remove results where the userKeysActionsArray is a string that contains integer like this way (JSON array) : [88254,8547,8569]

But when I tried to remove with a contains method and the NOT operator, I couldn't get the right number I expected.

I don't know how to resolve this problem.

Thanks a lot for your help.

int count;

var query = (from a in _db.ApplicationSet
             from h in a.ApplicationApprobationStatusHistorySet
             from u in a.Mission.MissionUserSet
             where a.Mission.isDeleted == false
                && a.Mission.isArchived == false
                && a.isRefused == false
                && a.ApplicationApprobationStatus.shortCode == "APPLICATION_APPROBATION_STATUS_LM_WAITING"
                && u.userKey == ContextUser.id
                && h.ApplicationApprobationStatus.shortCode == "APPLICATION_APPROBATION_STATUS_LM_WAITING" && h.isDeleted == false
              orderby a.applicationDate
              select new ApplicationCandidateListing
              {
                  applicationKey = a.id,
                  missionKey = a.Mission.id,
                  candidateKey = a.Candidate.id,
                  statusKey = a.ApplicationStatus.id,
                  clientKey = a.Mission.Client.id,
                  candidateFirstName = a.Candidate.firstName,
                  candidateLastName = a.Candidate.lastName,
                  clientLabel = a.Mission.Client.name,
                  statusLabel = a.ApplicationStatus.label,
                  missionLabel = a.Mission.label,
                  applicationDate = a.applicationDate,
                  isCVreserveList = a.isCVreserveList,
                  isCVviewed = a.isCVviewed,
                  refuseDate = a.refuseDate,
                  isShortListed = a.isShortListed,
                  candidateGroupShortcode = a.Candidate.CandidateGroup.shortCode,
                  approbationStatusIcons = a.ApplicationApprobationStatus.iconCSS,
                  approbationStatusShortCode = a.ApplicationApprobationStatus.shortCode,
                  isInternal = a.Candidate.isInternal,
                  lineManagerKey = ContextUser.id,
                  userKeysActionsArray = h.userKeysActionsArray,
                  commentCount = a.ApplicationCommentSet.Where(ac => ac.isPrivateLineManager != true).Count()
              }).Distinct();

string chance1 = "[" + ContextUser.id.ToString() + "]";
string chance2 = "[" + ContextUser.id.ToString() + ",";
string chance3 = "," + ContextUser.id.ToString() + ",";
string chance4 = "," + ContextUser.id.ToString() + "]";

var values = new[] { chance1, chance2, chance3, chance4 };
query.Where(q => !(values.Any(q.userKeysActionsArray.Contains)));  

count = query.Count();

return count;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can do it as below -

query.Where(q => !(
(q.userKeysActionsArray.Contains(chance1) ||
q.userKeysActionsArray.Contains(chance2) || 
q.userKeysActionsArray.Contains(chance3) || 
q.userKeysActionsArray.Contains(chance4))));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...