c# - LINQ not accepting Contains() -



c# - LINQ not accepting Contains() -

possible duplicate: 'contains()' workaround using linq entities?

using linq in c#, have next problem;

i need select rows big table, using 3 conditions: - "schooljaar" needs value, set before, - "p_bamatype" needs value not in list defined in settings (this stringcollection) - "p_stdgeb" needs value not in list defined in settings (this stringcollection)

i have code:

var set = (db.sa_opleiding.where(opleiding => opleiding.schooljaar == schooljaar && !properties.settings.default.admin_studiegebieden_exclude.cast <string>().tolist().contains( opleiding.p_stdgeb.tostring()) && !properties.settings.default.admin_studietypes_exclude.cast <string>().tolist().contains( opleiding.p_bamatype.tostring())) .select(opleiding => new opleidingmodel() { id = opleiding.p_opleiding, lannames = new dictionary <string, string>() { { "nl", opleiding. opleidingnl }, { "fr", opleiding. opleidingfr }, { "en", opleiding. opleidingen } } })) .tolist<opleidingmodel>(); homecoming set;

however, linq fails converting contains method. read others having same issue, can't seem find decent solution this. there solution problem described? need not in (collection of strings) linq equivalent.

if 1 of various duplicate answers doesn't help, here link 1 might. references extension linq-to-entities:

public static class queryextensions { public static iqueryable<tentity> wherein<tentity, tvalue> ( objectquery<tentity> query, expression<func<tentity, tvalue>> selector, ienumerable<tvalue> collection ) { parameterexpression p = selector.parameters.single(); //if there no elements clause, //we want no matches: if (!collection.any()) homecoming query.where(x=>false); if (collection.count() > 3000) //could move value config throw new argumentexception("collection big - execution cause stack overflow", "collection"); ienumerable<expression> equals = collection.select(value => (expression)expression.equal(selector.body, expression.constant(value, typeof(tvalue)))); look body = equals.aggregate((accumulate, equal) => expression.or(accumulate, equal)); homecoming query.where(expression.lambda<func<tentity, bool>>(body, p)); } }

there several others available.

edit

i've provided context code above, , here possible usage:

db.sa_opleiding.wherein(v => v.somecollection);

i haven't ever used specific extension method, they're based on same principle.

c# linq entity-framework

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -