Using in Like Operator in Entity Framework
Entity Framework is a great advancement to sql unfortunately some old keywords are not supported. But reading the documentation and google y...
https://www.czetsuyatech.com/2011/01/c-using-in-like-operator-ef.html
Entity Framework is a great advancement to sql unfortunately some old keywords are not supported. But reading the documentation and google you will find a lot of work arounds. Like for example in the case of IN operator.
Old
select * from table where field in (list);
For example in my recent requirement, I have a comma-delimited string: "A,B,C".
Old
select * from table where field in (list);
For example in my recent requirement, I have a comma-delimited string: "A,B,C".
IQueryable<MyModel> iQueryable = null; var temp = ""; var plainString = "A,B,C"; if (plainString.Length > 1) { //split "A,B,C" becomes an array of "A", "B", "C" var ids = plainString.TrimEnd(',').Split(','); //join the array and add single quotes "'A','B','C'" temp = string.Join("','", ids); temp = "'" + temp + "'"; } else { temp = "'" + plainString + "'"; } iQueryable = _myEntities.MyModel.Where("it.MyFieldHere IN {" + temp + "}");
Post a Comment