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...

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