Using IN like operator in Entity Framework
Tech-Today

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


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 + "}");




- How To Output Mysql Query Result Into A File
See sql script below: SELECT code, name, continent, region FROM country INTO OUTFILE 'c:/temp/countries.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n'; ...

- How To Create An Xsd And Xml Data From Model Entity In Java
The following code will show how to generate a xsd base on a given model and a sample xml with data. Let's assume you have a CustomerList model, which is an array of Customer. JAXBContext context; try { context = JAXBContext.newInstance(CustomerList.class);...

- Linq Dynamic And Or Statements
You usually need this on search form where you have to add a condition if a field is filled or not. This is how I do it: public static List Search(SearchViewModel param) { IQueryable matches = EntityMdl.SellOutMobiles; if (!string.IsNullOrEmpty(param.Client))...

- How To Write Left Join Sql On Entity Framework
In every limitation there is always a work around. For this specific limitation on entity framework 3.5 not having a left join. This is what I came up: For example you want to: SQL: select * from contact a left join country c on a.contactid=c.contactid...

- Allowing Url Query String In Codeigniter
As we all know codeigniter uses segment-based as url, example: Just like these: classname/methodname/parameter1/paramenter2, index.php/index/login/user/password Unfortunately, I was developing a web application that would accept payments via paypal. And...



Tech-Today








.