i’m starter in Repository Pattern in EntityFreamework in Bussiness Layer
i Have Get Methods
public IQueryable<Contract> GetAll()
{
var repository = new ContractsRepository(this.Context);
return repository.GetAll();
}
public IQueryable<Contract> GetAll(Func<Contract, bool> predicate)
{
var repository = new ContractsRepository(this.Context);
return repository.GetAll(predicate);
}
These are good,But I want to do computing on the field when a function return value to do what?
For example, I have 2 tables Table 1 and Table 2
- Table1 have a Field1 and Field 2
- Table2 have Field3 and Field4.
I want the Bussiness layer Table1 Get method to write the following
Field1 ,Field2,Field1+Field3,Field2+Field4
thanks
I disagree with Tony Hopkinson’s comment. You should not add a read-only property to your
Contactclass, because such a property cannot be used in LINQ to Entities, and hence aren’t suitable for methods which returnIQueryable.Instead, do something like:
The nice thing about this is that you can further compose the query:
…and the whole thing is done in SQL.