sarc...@gmail.com
unread,Jul 6, 2012, 11:59:35 AM7/6/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to blto...@googlegroups.com
In the following code the third query throws "Object reference not set to an instance of an object."
The first case uses the count property of the Orders list successfully and return the expected results.
The second case uses a previously defined predicate to query the length property of a string member successfully.
In the third loop, when the two patterns are mixed to blows up when query3 is iterated.
static void PredicateTest()
{
using (var db = new NorthwindDB())
{
var query1 = db.Employee.Where(p => p.Orders.Count < 2);
foreach (var employee in query1)
{
Console.WriteLine("{0} {1}", employee.EmployeeID, employee.FirstName);
}
Func<Employee, bool> fn2 = p => p.Address.Length > 10;
var query2 = db.Employee.Where(fn2);
foreach (var employee in query2)
{
Console.WriteLine("{0} {1}", employee.EmployeeID, employee.FirstName);
}
Func<Employee, bool> fn3 = p => p.Orders.Count < 2;
var query3 = db.Employee.Where(fn3);
foreach (var employee in query3)
{
Console.WriteLine("{0} {1}", employee.EmployeeID, employee.FirstName);
}
}
}