Sep
1
2009
.NET 4.0 // C# // EF

Entity Framework 4.0 - Running Ad hoc Queries or Commands

A nice addition to the latest version of ADO.NET Entity Framework is the ability to run ad hoc commands.  Two methods of the Entity Context have been introduced to accomplish that: ExecuteStoreQuery and ExecuteStoreCommand. The tricky part is passing the parameters. They are index based so the example below shows you how. string sql = "SELECT Col1, Col2 FROM MyUdf({0},{1});"; IEnumerable<MyComplexType> list = dbclient.ExecuteStoreQuery<MyComplexType>(sql, parameter1, parameter2);