Fetching related collections

Posts   
 
    
kingalef
User
Posts: 14
Joined: 10-Jul-2008
# Posted on: 03-Feb-2009 19:38:53   

Hi, it is me again simple_smile

I am continuing my exporation of LLBLGen and I have a question about fetching data from tables related to one. Specifically, I have this CTAC_USERS table that lists a bunch of users in my system. Each of these users belongs to a CTAC_DEPARTMENT. Is the code contained in the block "IS THIS THE BEST WAY?" the best I can use? It looks really complicated given what I want to get. Isn't there a simpler way?

var validUser = (from x in metadata.CTAC_USERS where (x.USERID.Trim().ToUpper() == aUserId.Trim().ToUpper()) && (x.PASSWORD == PasswordManager.EncodePassword(aPassword)) select x).First();

                aLoginInformation = new LoginInformation();
                aLoginInformation.UserId = validUser.USERID.ToUpper();

                // IS THIS THE BEST WAY?
                validUser.CTAC_DEPARTMENTS = (CTAC_DEPARTMENTSEntity)cobraAdapter.FetchNewEntity(
                    new CTAC_DEPARTMENTSEntityFactory(), 
                    validUser.GetRelationInfoCTAC_DEPARTMENTS());
               // END OF QUESTION

                aLoginInformation.Department = validUser.CTAC_DEPARTMENTS.NAME;

                aLoginInformation.UserName = validUser.FIRSTNAME + " " + validUser.LASTNAME;                    

                aSystemConfiguration = new SystemConfiguration();

In addition to that, I tried to see if validUser.GetRelatedData would do the loading for me, but it only returns a dictionary whose keys are null.

Any advice?

Thanks

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 03-Feb-2009 21:28:47   

I'm assuming you are using Adapter - if you were using SelfServicing you could simply call

validUser.CTAC_DEPARTMENT

to get the related entity.

In your case, invesitgate the use of pre-fetch paths on LINQ expressions to obtain a validUser with the CTAC_DEPARTMENT entity pre-loaded.

Matt

kingalef
User
Posts: 14
Joined: 10-Jul-2008
# Posted on: 03-Feb-2009 21:53:41   

I regenerated the code using SelfServicing and it's a lot easier now. I will go back and check the rest of the stuff you pointed out too.

Thanks

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 03-Feb-2009 21:57:25   

No Problem simple_smile