Print Page | Close Window

Why perform a SELECT * when I bind to a property of a related object?

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce Classic
Forum Discription: For .NET 2.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=216
Printed Date: 11-Apr-2026 at 12:03pm


Topic: Why perform a SELECT * when I bind to a property of a related object?
Posted By: Customer
Subject: Why perform a SELECT * when I bind to a property of a related object?
Date Posted: 12-Jul-2007 at 3:58pm
Why is it that when I bind to a relation, it performs a SELECT * rather than just retrieving the property I want?   I might just make a view in this situation.   Your thoughts?



Replies:
Posted By: IdeaBlade
Date Posted: 12-Jul-2007 at 3:58pm
I realize that you often want to bind only to a single property of a related object (e.g., the CompanyName of the Customer object related to the Order object on screen). You are disheartened that we fetch the whole related Customer object rather than just the property you will show. Isn't that inefficient?
 
DevForce always returns whole objects. You can fake it out (with dynamic objects for example) but that is not the norm and you have to work at it a bit to to get less than the whole object. Thus binding to the "CompanyName" property of an Order - via 'Customer.CompanyName" - results first in execution of something like "anOrder.Customer" - which returns a Customer object - and then binds to the "CompanyName" property of that Customer.
 
It would be inconsistent to do otherwise.
 
It would also be non-performant to do otherwise in many cases. Imagine that I bound to Customer.HqAddress.Street, Customer.HqAddress.City, Customer.HqAddress.Province, and Customer.HqAddress.PostalCode.  If we retrieved "just the properties", we'd be making at least four separate queries here.
 
Multiple roundtrips to the database are almost always more expensive than getting a little more data than you think you will need (e.g., bringing the whole Customer down rather than just the Customer.CompanyName). Caching saves many trips. Span queries (in which you fetch an Order's related Customer object at the same time that you fetched that Order) can save many more trips.
 
I hope this helps.



Print Page | Close Window