Entity Framework 5 Update 4

I had a problem with the Where clause in the search, in my original version of EF4 I could add a Where clause with two parameters, a where clause (a string predicate) and an ObjectParameter list, for example

var query = context.entities.Where(WhereClause.ToString(), Params.ToArray()); 

since my upgrade to EF5, it seems that I don’t have such an opportunity, did I miss something?

This was originally used to create a dynamic where clause, such as "it.entity_id = @entity_id", and then store the value of the variable in ObjectParameter.

I hope that I don’t have to rewrite all the search queries that were built in this way, so any help would be greatly appreciated.

Greetings

+4
source share
1 answer

To use ESQL with DbContext, you will have to "reset" the ObjectContext.

 var objectContext = ((IObjectContextAdapter)context).ObjectContext; var query = objectContext.CreateQuery<MyEntity>( WhereClause.ToString(), Params.ToArray()); 
+1
source

Source: https://habr.com/ru/post/1444623/


All Articles