Let's say I have a HospitalEntity and it has a 1:m relationship with LocationEntity. Obviously, a HospitalEntity has many other properties that are inherent to that entity (HospitalName, etc).
I looked in the manual and found information about "Prefetch Paths" but I'm not necessarily trying to prefetch them. I have an ASP.NET MVC app and I am using a service layer to actually run the LINQ queries but I am passing regular LLBLGen Entities around back to my MVC controllers (in other words, currently I don't use any kind of DTO, just LLBLGen Entities).
I thought by running this code:
LinqMetaData metaData = new LinqMetaData(adapter);
HospitalEntity hosp =
(from h in metaData.Hospital
where h.HospitalId = 42
orderby h.Name
select c).SingleOrDefault()
I could then run some code like this:
foreach(RoomEntity r in hosp.Rooms)
{ ... }
I thought this would cause the hosp.Rooms collection to be populated but it's not.
I use the WithPath extensions and was able to populate this collection.
However, is this the best way? I need to have something kind of flexible. My issue is that, as I said, I have a service layer, so I have a class, say ServiceLayer that has methods that perform the LINQ queries as well as create/update/delete operations and are called by the Controllers.
So I have a function in the ServiceLayer class like:
public HospitalEntity GetHospital(long id)
It would be nice if the controller could simply call properties on the returned object to get access to the related entities. I definitely don't want my LINQ queries to occur anywhere other than in my ServiceLayer.
What I've done for now is modify my GetHospital() type methods to go ahead and use the WithPath for whatever relation I need.
This is not optimal as not every call to GetHospital() will require these relations. However, I don't want to have a bunch of methods like GetHospital(), GetHospitalWithRooms(), GetHospitalWithDoctors(), etc.
What's the best way to do this? Can my GetHospital() style methods accept some kind of field list and my LINQ queries be given WithPaths dynamically or something similar?
The only thing is I have to use LINQ. I can't really use the old style query API (which I realize can accept these kinds of lists one way or another).
Anyway, thanks for any help.