I have a pattern that I would like to implement. Currently I have implemented it using LLBLGen but with one major caveat and a few minor ones.
The issue is to do with mapping from my entity objects to my model objects. Heres an example of what I want to achieve:
public IQueryable<Office> Find()
{
LinqMetaData meta = new LinqMetaData(Adapter);
return (from c in meta.Office
select AutoMapper.Mapper.Map<OfficeEntity, Office>(c));
}
This part would work in LLBL if i took Automapper out and manually mapped from my entity to my model class. Automapper issue aside (this is needed as I don't want to be constantly mapping for all my dataaccess objects for each and every query) (Frans has already told me this might work in v3).
However the behaviour I get with LLBL is if I apply any further modifications to the return IQueryable they are applied in memory. See this example of calling this method, modifyign the result and then enumerating it. (i havent actually compiled any of these examples so might be a few silly mistakes)
var offices = officeService.Find();
offices = offices.Where(p => p.PostalAddress.Contains("melbourne")).OrderBy(p => p.OfficeNo);
var foo = offices.ToList();
If I were still working with OfficeEntity instead of Office the ToList call would execute a SQL statement with the ORDER BY and WHERE in it. But because I have have mapped from the original entity what ends up happening is the inital query is executed (a vanilla select statement) and then the orderby and where are implemented in memory. Which is really bad for obvious reasons.
Now my initial mapping is just a series of fields from the original entity. I can see the issue though, it is difficult for the "system" to know that Order.PostalAddress is actually OfficeEntity.PostalAddress. What it really needs to do is internally treat Office.PostalAddress like a Func<string, OfficeEntity> (p=>p.PostalAddress) (or maybe I mean an Expression) that it can reference and map to the PostalAddress address column of the Office entity. It could also handle more complex mappings this way (like (p=>p.PostalAddress + " - " + p.OfficeNo) to SELECT PostalAddress + ' - ' + OfficeNo [PostalAddress]) this way.
Without this I am finding Models a bit of a pain. I don't want to reference anywhere the entity classes from my DomainService consuming code... I kind of feel like I'm asking Santa Claus for a Ferrari but I'm asking anyway
Can live without the AutoMapper compatibility but it sure would be nice to have.