views:

107

answers:

1

hi

i ask subsonic for a table in my database it returs the table and all other tables connected threw foreign keys,

cant i stop it bringing back all the extra table info??

here is my code:

[WebMethod]
[ScriptMethod]
public List<DealEquipment> GetDealEquipment(Guid DealID)
{
    List<DealEquipment> dealEquipmentList = new List<DealEquipment>();
    Deal deal = new Deal(DealID);
    DealEquipmentCollection dealEquipmentCollection = deal.DealEquipmentRecords();

    foreach (DealEquipment dealEquipment in dealEquipmentCollection)
    {
        DealEquipment dealEquipmentTemp = dealEquipment;
        DealEquipmentSerialNumberCollection dealEquipmentSerialNumberCollection =     new      DealEquipmentSerialNumberCollection().Where(DealEquipmentSerialNumber.Columns.FkDealEquipmentID, Comparison.Equals, dealEquipmentTemp.PkDealEquipmentID).Load();
        dealEquipmentTemp.objSerialNumber = new List<DealEquipmentSerialNumber>();
        foreach (DealEquipmentSerialNumber dealEquipmentSerialNumber in dealEquipmentSerialNumberCollection)
        {
            dealEquipmentTemp.objSerialNumber.Add(dealEquipmentSerialNumber);
        }
        dealEquipmentList.Add(dealEquipmentTemp);
    }

    return dealEquipmentList;
}

The dealEquipmentList that i return is suppose to only contain my foreinkey to supplier, but the supplier tables info is also included

this is a problem since the supplier object contains huge binary images

i try to set it to null but it is ignored

any ideas?

+2  A: 

It doesn't actually contain the object. What happens is that when you access the Supplier property on the DealEquipment it sends a new request to the DB to fetch the Supplier with the ID you chose, via FetchByID(int). You can take a look at the generated classes to see with your own eyes, if you'd like.

(This answer is based on version 2.1.1.0 .)

krdluzni
thankyou for the quick responsei am not sure that i understandwhat should i do then? i get the max json lenght error if i just leave it.when i look at the object before return in the watch, i see the binary image
REEVESTRIFE
I think I understand, but am not fully certain how to handle it. I think what is happening is that when the list gets converted to json, the system uses reflection to access all properties. This would trigger the DB call,fetch the related data, and continue to cascade further with conversions. If this is true, you may need to move the properties you wish to see into a struct of your own, and return that instead. Not a very pleasant solution, I'm afraid, but it's the only one I see. Maybe someone else will respond and have an alternative, or more certain solution. Or at least confirm this one.
krdluzni
As an additional point, you may want to take advantage of partial classes to add a function that generates the above mentioned struct to the DealEquipment class.
krdluzni