Design question - Checking if related entity exists

Posts   
 
    
KIT
User
Posts: 59
Joined: 04-Apr-2007
# Posted on: 24-Jul-2007 15:01:53   

Hi.

I'm having a question related to design. Let's assume that we have 2 tables in the database:

  1. Document_properties --> fetching this table is fast as the size of the contained data is small.
  2. Document_data --> fetching this table is extremely slow as the contained documents are very big, lets say >100MB. So it takes a long time to transfer them from the database server to the client.

NOT every document_property has document_data.

Now I want to load all document_property entities with the information, if a document_data is linked to it. Something like this:

SELECT dp.*, hasData = dd.id  FROM document_properties dp 
    LEFT OUTER JOIN document_data dd on dp.id = dd.refId

Whats the best way to do that? Is it possible to tell LLBLGen that a specific field shouldn't be fetched from the db (the actual document data in this case)? Is there a field that can be prefetched that just checks the existence of a related entity?

Thanks in advance for your help. simple_smile

Cheers.

jbb avatar
jbb
User
Posts: 267
Joined: 29-Nov-2005
# Posted on: 24-Jul-2007 15:13:52   

Hi,

do you use adapter or selfservices?

The best way is to create a relation between document_property and document_data and not using prefetch path. But If you want to load all document_property entities with the information, if a document_data is linked to it, you just need to use an INNER JOIN relation.

KIT
User
Posts: 59
Joined: 04-Apr-2007
# Posted on: 24-Jul-2007 15:18:48   

I use adapter.

The point is that I don't want to instanciate document_data entities, as the size of them is huge. I just want to have THE INFORMATION if the entity exists or not.

To just make a query and to load both entity types is not the problem. What I actually want to do is to optimize performance. simple_smile

jbb avatar
jbb
User
Posts: 267
Joined: 29-Nov-2005
# Posted on: 24-Jul-2007 15:29:09   

Hello,

why don't you just get an entityCollection of Document_properties? For each entity, you could check if your fk is null so you can know if you have(or not) document_data linked.

arschr
User
Posts: 894
Joined: 14-Dec-2003
# Posted on: 24-Jul-2007 15:48:00   

In v2.5 (now in beta) you can specify columns that shouldn't be loaded automatically (like you large documents).

Also using filters and relations you should be able to retrieve only entityAs that have or don't have entityBs without retrieving entityBs

KIT
User
Posts: 59
Joined: 04-Apr-2007
# Posted on: 24-Jul-2007 16:00:14   

@jbb: That would work if the fk were in document_properties and the pk in document_data. But it's the other way round.. flushed

@arschr: 1. Well, I work with v2.0.. wink But that would solve the problem! stuck_out_tongue_winking_eye 2. Your suggestion does not exactly solve my problem. I want to get ALL entityAs and just the INFORMATION if there are linked entityBs or not.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 25-Jul-2007 12:22:08   

I think you need to to read the section titled Extending the CustomerEntityFactory in the following article: http://weblogs.asp.net/fbouma/archive/2006/06/09/LLBLGen-Pro-v2.0-with-ASP.NET-2.0.aspx

KIT
User
Posts: 59
Joined: 04-Apr-2007
# Posted on: 25-Jul-2007 13:00:11   

I haven't tried a custom factory yet but I think that answers my question. simple_smile I even didn't know that this is possible. disappointed

Thanks a lot! sunglasses