Reputation: 845
It is a good pattern to separate the way objects are persisted from the business logic. If I expose how objects are persisted in the database to the business logic, then when I change how these objects are persisted, I will have to change the business logic, making them tightly coupled.
With that being said, suppose that the business logic uses Foo as an object, and suppose that the DAL (using EF) uses FooDbModel as an object for persisting. Building the CRUD operations with the repository pattern is very simple: Get Foo
object, build FooDbModel
, do whatever is needed, and build Foo
back, and return it.
But when Find
functionality is little more involving. Ideally, I want to do something like:
Repository.Find(f => f.Name == "something");
where f
is of type Foo
(not FooDbModel
). Is that possible with EF? I don't want to pass f
where if is of type FooDbModel
because that is exposing the data persistence to the BL.
Is there a trick to do that?
Upvotes: 1
Views: 1112
Reputation: 845
@IvanStoev solved the problem.
Basically, I will need to do a select and then a where.
To quote him:
Not if you do it on IQueryable. Not sure how exactly your methods are structured, but the implementation of the Find method I see is something like context.Set().Select(m => new Foo { ... }).Where(f => ...) which should translate to SQL.
Upvotes: 1