Child_Fetch of object fetched from multiple entities

Child_Fetch of object fetched from multiple entities

Old forum URL: forums.lhotka.net/forums/t/10315.aspx


KevinManx posted on Thursday, April 28, 2011

I have a object that is populated from multiple EF entities:

RiderInfo

Id                               from Rider entity.
Name                       from Rider (FirstName LastName).
NationalityName    from Nationality entity.

I have the Fetch method:

 

private void DataPortal_Fetch(int criteria)
    {
        var rider = Rider.GetRider(criteria);
        Id = rider.Id;
        Name = string.Format("{0} {1}", rider.FirstName, rider.LastName);
        NationalityName = Nationality.GetNationality(rider.NationalityId).NationalityName;
    }

 

Do I have this correct or am I missing something (very possible)?

I want to build a RiderInfoList object and am lost on how to implement the Child_Fetch method to call from the list's Fetch method:

private void Child_Fetch(System.Data.IDataReader data)

Thanks

RockfordLhotka replied on Thursday, April 28, 2011

RiderInfo is a read-only object, and RiderInfoList is a read-only list of RiderInfo?

Normally you'd do the database query in the RiderInfoList class's DataPortal_Fetch, so all the data is retrieved in one database call. In your case this will require a join or a predictive load of the secondary entity - at least to be efficient.

Then the RiderInfo class will have a Child_Fetch method that accepts the entity object, not a data reader - at least that's the simple scenario assuming you don't care about having a pluggable DAL.

The Using CSLA 4: Data Access ebook walks through this process, but assumes a pluggable DAL. So in that book I convert the EF entities into either DTOs or a data reader - the idea being that entity objects aren't abstract enough to support different databases or mock data (though EF 4.1 now makes that pretty realistic with code-first entities).

So basically you need to decide if you want:

  1. A non-pluggable DAL - in which case you can pass designer-generated entities into Child_Fetch
  2. A pluggable DAL using a DTO or data reader interface like in the Data Access ebook
  3. A pluggable DAL using the new code-first entity feature of EF 4.1

In each case though, the list does the query, and passes an entity, DTO, data reader, or code-first entity to the Child_Fetch method.

KevinManx replied on Thursday, April 28, 2011

Cheers Rocky. I was going around in circles on this and kept going off the wrong way. Implemented and now working.

Thanks.

Copyright (c) Marimer LLC