How to convert DbSet in Entity framework to ObjectQuery

I found the answer. Of course, it is possible to convert DbSet in Entity framework to ObjectQuery using the below lines of code. ObjectContext objectContext = ((IObjectContextAdapter)db).ObjectContext; ObjectSet<Request> objectSet = objectContext.CreateObjectSet<Request>(“Requests”); where, db – Context class inherting from DbContext. Requests – DbSet<Request> defined in Context class. objectSet – Can now be passed as ObjectQuery.

Entity Framework 4.1: Unable to cast from DbQuery to ObjectQuery

That is because your _database is derived from DbContext and your AccountsOfMonth is DbSet<>. In such case you cannot use ObjectQuery directly because DbSet<> produces DbQuery<> which is not convertible to ObjectQuery<>. You must either use DbQuery<> directly: var result = from acm in this._database.AccountsOnMonth where ((acm.Year == year) && (acm.Month == month)) select acm.Id; … Read more

Entity Framework and multiple schemas

While doing some research about Entity Framework I came across the following post: http://romiller.com/2011/05/23/ef-4-1-multi-tenant-with-code-first/ It doesn’t quite give me a single dbContext to work with but it does only use a single connection (which was my reasoning behind not wanting to use multiple dbContexts). After setting up the following code: public class oraDbContext : DbContext … Read more

How to use Entity Framework to map results of a stored procedure to entity with differently named parameters

From Entity Framework Code First book (page 155): The SQLQuery method always attempts the column-to-property matching based on property name… None that the column-to-property name matching does not take any mapping into account. For example, if you had mapped the DestinationId property to a column called Id in the Destination table, the SqlQuery method would … Read more

Set database collation in Entity Framework Code-First Initializer

Solution with a command interceptor It is definitely possible, though it’s a bit of a hack. You can alter the CREATE DATABASE command with a command interceptor. Il will intercept all the commands sent to the database, recognize the database creation command based on a regex expression, and alter the command text with your collation. … Read more