I am trying to build a decoupled domain model. My (abstract) domain model defines an entity, 'Product' for example, and then my concrete SQL implementation provides a conversion method to that Domain entity.
For example:
public interface IDomainEntity<T> where T : class
{
T ToDomainEntity();
}
My concrete SQL class then implements that interface:
public partial class Product : IDomainEntity<Domain.Product>
{
public Domain.Product ToDomainEntity()
{
return new Domain.Product
{
ProductId = this.ProductId,
...
};
}
}
From my product domain service, I want to be able to expose a general filter method
public virtual IQueryable<T> Filter(Expression<Func<T, bool>> predicate)
{
return GetAll().Where(predicate);
}
Where, in this case, T is of type Domain.Product. The problem I have is that in the SQL repository implementation, I need to convert the expression from type Domain.Product to type Sql.Product so I can use it against my Linq to Sql table.
Is it possible to take one expression base and convert it to another:
Expression<Func<Domain.Product, bool>>
to
Expression<Func<Sql.Product, bool>>
Apologies in advance if this doesn't make sense.