CodeSmith Community
Your Code. Your Way. Faster!

DeepLoad System.NullReferenceException - probably a newbie q

Latest post 07-05-2008 5:03 AM by scudsucker. 3 replies.
  • 07-03-2008 10:29 AM

    DeepLoad System.NullReferenceException - probably a newbie q

     Hi,

     Apologies for what is no doubt a newbie question - I have searched and found two threads here and here. However, they have not helped me solve my problem. In theory, my problem is more or less identical to the first link. 

    I have two tables, Apartment and ApartmentType:

    Apartment has

    intApartmentID int primary key

    intApartmentType int foreign key

    vchApartmentName varchar

     

    ApartmentType has

    intApartmentType int primary key 

    vchApartmentType varchar 

     

    So, I want to get a collection of Apartments, deeploading the ApartmentType. I know that a record exists for IntApartmentID=6, I have ensured that the record in question has an existing record as its foreign key.

    ( edited for brevity)


            TList<Apartment> aptList = DataRepository.ApartmentProvider.Find("IntApartmentID=6");
            DataRepository.ApartmentProvider.DeepLoad(aptList, true, DeepLoadType.IncludeChildren, new Type[ { typeof(TList<ApartmentType>) });

            Response.Write(aptList[0].VchName + "<br />");
            Response.Write(aptList[0].IntApartmentTypeId + "<br />");
            Response.Write(aptList[0].IntApartmentTypeIdSource.VchApartmentType);  //   <-- Error is thrown by this line

     

     This results in "System.NullReferenceException: Object reference not set to an instance of an object." If I comment out the line, I can access the name and type.

    I have also tried

          DataRepository.ApartmentProvider.DeepLoad(aptList, true, DeepLoadType.IncludeChildren, typeof(TList<ApartmentType>) );  

    and

        DataRepository.ApartmentProvider.DeepLoad(aptList, true, DeepLoadType.IncludeChildren, typeof(ApartmentType) ); 

    (the last, as it is a 1-->1 relationship)

     In each case, the  IntApartmentTypeIdSource.VchApartmentType is null.

     Coudl someone show me the error of my ways?

     Thanks,

    Anthony 

     

    * apologies for Hungarian notation, it is what I am used to- but it doesnt seem to fit .netTiers so well!

    • Post Points: 5
  • 07-04-2008 3:33 AM In reply to

    Re: DeepLoad System.NullReferenceException - probably a newbie q

    Well, I have fixed it, but it seems clumsy to me. I am now populating the apt.IntApartmentTypeIdSource manually - is that not what DeepLoad is supposed to do?

    TList<Apartment> aptList = DataRepository.ApartmentProvider.Find("IntApartmentID=6");
            DataRepository.ApartmentProvider.DeepLoad(aptList, true, DeepLoadType.IncludeChildren, new Type[ { typeof(TList<ApartmentType>) });

            Response.Write(aptList[0].VchName + "<br />");
            Response.Write(aptList[0].IntApartmentTypeId + "<br />");

    // Manually populate the  source:

           apt.IntApartmentTypeIdSource =
                DataRepository.ApartmentTypeProvider.GetByIntApartmentTypeId(apt.IntApartmentTypeId);

            Response.Write(apt.IntApartmentTypeIdSource.VchApartmentType); // Prints correct value.

     

     

     

    • Post Points: 35
  • 07-04-2008 5:26 PM In reply to

    • fweeee
    • Top 25 Contributor
    • Joined on 08-08-2007
    • Posts 176
    • Points 4,403

    Re: DeepLoad System.NullReferenceException - probably a newbie q

     scudsucker,

    If I understand correctly, I am pretty sure the command you were using: 

    DataRepository.ApartmentProvider.DeepLoad(aptList, true, DeepLoadType.IncludeChildren, new Type[ { typeof(TList<ApartmentType>) });

    was never going to work. Another one you tried (in your first post) is:

    DataRepository.ApartmentProvider.DeepLoad(aptList, true, DeepLoadType.IncludeChildren, typeof(ApartmentType) ); 

    This one I think should have worked. You are only trying to load one ApartmentType per  Apartment, so there is no need for the TList bit (If you were deep loading Apartments for an ApartmentType record, then you would use TList, as you are trying to load multiple Apartments for the ApartmentType).

    I cant tell you why the deepload isnt working - but I try to avoid deeploads. I have found them to be a tad unreliable. One problem I found with deeploads that if the record I was deeploading was new, none of the children records would load.

    • Post Points: 35
  • 07-05-2008 5:03 AM In reply to

    Re: DeepLoad System.NullReferenceException - probably a newbie q

     Hi, thanks. None of the methods I listed worked- and as I have a work-around, I wont pursue it too much.

     Deepload does seem like a cool feature, perhaps it is a little buggy still.

    • Post Points: 5
Page 1 of 1 (4 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems