You are developing an application that uses the Microsoft ADO.NET Entity Framework to retrieve order
information from a Microsoft SQL Server database. The application includes the following code. (Line numbersare included for reference only.)
01 public DateTime? OrderDate;
02 IQueryable<Order> LookupOrdersForYear(int year)
03 {
04 using (var context = new NorthwindEntities())
05 {
06 var orders =
07 from order in context.Orders
08
09 select order;
10 return orders.ToList().AsQueryable();
11 }
12 }
The application must meet the following requirements:
return only orders that have an OrderDate value other than null.
return only orders that were placed in the year specified by the method year parameter
not raise an exception
You need to ensure that the application meets the requirements. Which code segment should you insert at line
08?
A.
where order.OrderDate.Value != null && order.OrderDate.Value.Year >= year
B.
where order.OrderDate.Value == null && order.OrderDate.Value.Year == year
C.
where order.OrderDate.HasValue && order.OrderDate.Value.Year >= year
D.
where order.OrderDate.Value.Year == year
Mistake in C, should be order.OrderDate.HasValue && order.OrderDate.Value.Year == year if the question is to be believed.
exactly!