473,403 Members | 2,183 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Dlinq question

Question concerning deferred evalution. If one has a customer table
and an orders table in the database and the latter table has a customer
id assocatiated with it, when a query is executed like this:

IEnumerable<Customer> customers = from c in db.Customers
where c.CustomerId == customerId
select c

Customer[] arrCust = customers.ToArray<Customer>();
Customer cust = arrCust[0];

All of the orders for the customer are apparently loaded as well. Is
there a way to NOT get all of the orders until a later time, say if you
want just the customer data on one page, and when an orders button is
pressed and another page is requested, then select the orders for that
particular customer in the other page?

If I enumerate the customers collection without executing the query by
calling ToArray and just return the first customer, the orders
collection is still populated.

foreach(Customer c in customers)
{
// For test.
return c;
}

c.Orders collection is still filled.

How is this different from using the Including statement,
customers.Including(c => c.Orders) if they both get all the data
anyways?

Apparently, deferred query execution is not making sense to me because
it looks like nothing is deferred.

Thanks,

Hammad

Apr 21 '06 #1
1 1298
TMK, the orders are not loaded. They are loaded as a seperate db query when
you access the contained list. Set db.Log = Console.Out to see the
different queries.

--
William Stacey [MVP]

"ha****************@gmail.com" <ha*********@gmail.com> wrote in message
news:11**********************@z34g2000cwc.googlegr oups.com...
| Question concerning deferred evalution. If one has a customer table
| and an orders table in the database and the latter table has a customer
| id assocatiated with it, when a query is executed like this:
|
| IEnumerable<Customer> customers = from c in db.Customers
| where c.CustomerId == customerId
| select c
|
| Customer[] arrCust = customers.ToArray<Customer>();
| Customer cust = arrCust[0];
|
| All of the orders for the customer are apparently loaded as well. Is
| there a way to NOT get all of the orders until a later time, say if you
| want just the customer data on one page, and when an orders button is
| pressed and another page is requested, then select the orders for that
| particular customer in the other page?
|
| If I enumerate the customers collection without executing the query by
| calling ToArray and just return the first customer, the orders
| collection is still populated.
|
| foreach(Customer c in customers)
| {
| // For test.
| return c;
| }
|
| c.Orders collection is still filled.
|
| How is this different from using the Including statement,
| customers.Including(c => c.Orders) if they both get all the data
| anyways?
|
| Apparently, deferred query execution is not making sense to me because
| it looks like nothing is deferred.
|
| Thanks,
|
| Hammad
|
Apr 22 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Lei Jiang | last post by:
1) Is it support other database other than SQL Server, such as Oracle, Sybase? 2) How about the performance? Does it relay on reflections to bind the value from databse to Entity object? ...
7
by: Senna | last post by:
Hi Have a question about DLinq. The example code floating around looks like this: Northwind db = new Northwind(@"C:\...\northwnd.mdf"); var custs = from c in db.Customers where c.City ==...
3
by: Chiranjib | last post by:
I have the following queries/Observations about DLINQ. 1. I could not find any direct way of handling many to many relations. Suppose if User and Role are related by a join table UserRole then I...
0
by: Scott Nonnenberg [MSFT] | last post by:
This is our first official DLinq chat. We're still early in the planning and development stage for this very cool technology, so we can react to your feedback much more easily. Show up and tell us...
0
by: Scott Nonnenberg [MSFT] | last post by:
The DLinq team will be ready and waiting for your questions and comments at this date and time at this location: http://msdn.microsoft.com/chats/chatroom.aspx. This is otherwise known as a chat -...
0
by: Scott Nonnenberg [MSFT] | last post by:
Show up and talk to members of the DLinq team. What's DLinq, you ask? Well, to understand that you'll need to know what LINQ is - you can start with the blurb below, read more about it here:...
4
by: Brett Romero | last post by:
I've downloaded the DLINQ samples from Microsoft and have always been able to compile these in VS.NET 2005 Pro. I have a new project that I added DLINQ references to and put in a simlpe query. It...
19
by: Andrus | last post by:
I need to repeatedly execute same queries which returns single entity by id, like: Customer cust = (from c in db.Customers where c.CustomerID=="AIRBU" select c).SingleOrDefault(); DLinq...
9
by: Marc Gravell | last post by:
How to fix ? Write it the way that you know works... (i.e. the one you commented out), or write that parses the input string doing a Split on '.', and uses reflection to navigate the child...
2
by: Andrus | last post by:
I need to pass DLinq query to RDLDEsigner. RDLDesigner does not accept IQueryable<T>. It accepts SQL select statement in plain text format as data source. How to get SELECT statement which...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.