vendredi 13 mars 2015

How to pass an expression to a LINQ query as a parameter

I have a few statements like these:



if (mediaCode.IndexOf(',') > 0) {
entries = entries.Where(c => mediaCode.Contains(c.Mediacode));
}
else {
entries = entries.Where(c => c.Mediacode == mediaCode);
}


then:



if (contentType.IndexOf(',') > 0) {
entries = entries.Where(c => contentType.Contains(c.Contenttype));
}
else {
entries = entries.Where(c => c.Contenttype == contentType);
}


I would like to create a function where i just pass the string and the property, something like: MethodName(contentType, c.Contenttype)


How could this be done?






Aucun commentaire:

Enregistrer un commentaire