Reputation: 4727
In “Programming Entity Framework”, 2nd edition by Julia Lerman, in chapter dedicated to Entity SQL, p. 115, we have the following example of using query builder method to do projection using EF 4.1 .Where
and .Select
with string parameters:
ObjectQuery<DbDataRecord> contacts = context.Contacts
.Where("it.FirstName='Robert'")
.Select("it.Title, it.FirstName, it.LastName");
I am using Entity Framework 6, .Net 4.6, VS 2015. The compiler complains that there are no .Where
and .Select
that accept string parameters, only lambdas. Is there any solution how to follow this book example?
Upvotes: 0
Views: 752
Reputation: 48975
The example appears to be about the old ObjectQuery
API, which shouldn't really be used now. It's still possible to use it with EF6.x though, with something like the following:
ObjectContext objectContext = ((IObjectContextAdapter)conte).ObjectContext;
ObjectSet<DbDataRecord> objectSet = objectContext.CreateObjectSet<DbDataRecord>("DbDataRecords");
// Async version: var res0 = await objectSet.Where("it.FirstName='Robert'").ToListAsync();
var res0 = objectSet.Where("it.FirstName='Robert'").ToList();
That said, you really should use the lambda instead with the new DbContext
API.
Upvotes: 2