LINQ to SQL Instantiation
page 6 of 8
by Brian Mains
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 2602/ 236

Query Operations

When using an operation like the Where() method in the following code:

Listing 8

_context.Customers.Where(i => i.AccountNumber == "T2341003");

The results that come back are a DataQuery object. This object is not null for queries that even return no results. So the following code works:

Listing 9

customers = _context.Customers.Where(i => i.AccountNumber == "XXXX");
Assert.AreEqual(0, customers.Count());
 
count = 0;
foreach (Customer customer in customers)
{
      count++;
      //Test that iterating through collection is OK
}
Assert.AreEqual(0, count);

What this means is that the Where() method returns no records, because the account number does not exist. The result count is an empty query, but you can continue to use this object freely, as shown above, and not have to worry about a null reference exception.


View Entire Article

Article Feedback

Title:  
Name:  
Url: ( Optional )
Comment:  
Please add 3 and 7 and type the answer here:

User Comments

No comments posted yet.






Ads Powered by Lake Quincy Media
Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2008 ASPAlliance.com  |  Page Processed at 7/5/2008 8:20:08 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search