code_junkie

Mapping computed properties in Linq-to-SQL to actuall SQL statements

Nov 11th, 2011
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. var activeContracts = customer.Contracts.Where(w => w.ContractEndDate == null);
  2.  
  3. var activeContracts = customer.ActiveContracts;
  4.  
  5. var singleContractCustomers = db.Customers.Where(w => w.ActiveContracts.Count() == 1);
  6.  
  7. public static Expression<Func<Customer, bool>> HasActiveContract
  8. {
  9. get { return cust => cust.Contracts.Count() == 1; }
  10. }
  11.  
  12. var filtered = db.Customers.Where(Customer.HasActiveContract);
  13.  
  14. public IQueryable<Customer> CustomersWithActiveContract
  15. {
  16. get { return Customers.Where(Customer.HasActiveContract); }
  17. }
  18.  
  19. {SELECT [t0].[CustomerID], [t0].[cFirstName], [t0].[cLastName]
  20. FROM [dbo].[Customers] AS [t0]
  21. WHERE ((
  22. SELECT COUNT(*)
  23. FROM [dbo].[Contracts] AS [t1]
  24. WHERE (([t1].[ContractEndDate] > @p0) OR ([t1].[ContractEndDate] IS NULL)) AND ([t1].[cId] = [t0].[cId])
  25. )) > @p1
  26. }
Add Comment
Please, Sign In to add comment