0

I’m having issues creating an Where clause using C# and lambdas.

I have the following method GetRecommendedstudents(Guid studId)

The variable string filtersByRoles can hold a comma-delimited value such as: "xp,windows,windows8 or "xp,windows,windows8,windo " etc..

I then have the following C# lambda query:

I need get data from database by comparing 2 fields.

enter code here  
 var student= DataContext.students.Find(studId);
 ex: var x = DataContext.students.Where(L => (L.job == student.studentJobLocation)).AsQueryable();

Next i want comapare student know os("xp,windows,windows8 )

 ex: var y = x.students.Where(L => (s => (s.jobOperaitngsys.Split(',') == student.studentknowOS)), StringSplitOptions.RemoveEmptyEntries);

How to compare this to fields? jobOperaitngsys and studentknowOS

1
  • Please describe the problems you found when you tried to use the sample code. Commented Jan 25, 2014 at 6:25

1 Answer 1

1

you should use contain. because split returns string array.

 s.jobOperaitngsys.Split(',').Contains(student.studentknowOS)
Sign up to request clarification or add additional context in comments.

3 Comments

StringSplitOptions.RemoveEmptyEntries ,here it's showing error that cant used as statement.
y = x.students.Where(s => s.jobOperaitngsys.Split(',').Contains(student.studentknowOS));
hi,it geting exception LINQ to Entities does not recognize the method 'System.String[] Split(Char[], System.StringSplitOptions)' method, and this method cannot be translated into a store expression.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.