Helo,
i have spent some time now to solve a problem for which i have no solution till now. I have a predefined very huge database, whose structure is fixed. I use the repository pattern to create a abstraction layer between service code and database logic. The problem is, that i need to apply some processing to the database object before passing them out of the repository. Thus i can't use the Linq Entities directly.
Basically a repository method looks like this:
public IList<Bookingcode> FindBookingcode(int id) {
return (from b in _db.BOOKINGCODE
where b.ID == id
select new Bookingcode {
Id = b.ID,
Name = b.NAME.Trim()
}).ToList();
}
This works good so far. But i have a lot of objects which should be individually composed. FindBookingcode() should return a nearly complete object with other objects like catalogs and so on. My Problem now is that i have to rewrite the mapping a lot of times like in this example:
public IList<Bookingcode> FindBookingcode(int id) {
return (from b in _db.BOOKINGCODE
join c1 in _db.CATALOG on b.CATALOGID equals c1.ID
where b.ID == id
let refs = (
from bc1 in _db.BOOKINGCODE
join p in _db.PACKAGE on bc1.ID equals p.BOOKINGCODE
join bc2 in _db.BOOKINGCODE on p.PACKAGEREF equals bc2.ID
join c in _db.CATALOG on bc.CATALOGID on bc2.CATALOGID equals c.ID
where bc1.ID == b.ID
select new PackageInfo {
ID = p.ID
BookingcodeRef = new Bookingcode {
ID = bc2.ID,
Catalog = new Catalog { ID = c.ID }
}
})
select new Bookingcode {
ID = b.ID,
PackageInfo = refs.ToList()
}).ToList();
}
I also have some L2O processing within the repository which assembles the returned objects. Another thing i have no cool solution for, is a way to tell the repository what it should fetch, like FindBookingcode(id, includePackageInfo, includeCatalog).
So here are the questions:
1) Is this approach totally stupid?
2) Can you guide me to a solution which makes the remapping simpler?
3) How to implement the DDD's criteria mechanism
thanks