Guest User

LINQ to SQL and the repository pattern

a guest
Feb 26th, 2012
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. //Custom wrapper class.
  2. namespace Data
  3. {
  4. public class Customer
  5. {
  6. public int Id {get;set;}
  7. public string Name {get;set;}
  8. public IList<Address> Addresses {get;set;}
  9. }
  10. }
  11.  
  12. //Linq-Generated Class - severly abbreviated
  13. namespace SqlRepository
  14. {
  15. public class Customer
  16. {
  17. public int Id {get;set;}
  18. public string Name {get;set;}
  19. public EntitySet<Address> {get;set;}
  20. }
  21. }
  22.  
  23. //Customer Repository
  24. namespace SqlRepository
  25. {
  26. public class UserRepository : IUserRepository
  27. {
  28. private _db = new DB(); //This is the Linq-To-Sql datacontext
  29.  
  30. public IQueryable GetCusomters()
  31. {
  32. return
  33. from c in _db.Customers
  34. select new Customer // This is the wrapper class not the gen'd one
  35. {
  36. Id = c.Id,
  37. Name = c.Name,
  38. Addresses = new LazyList(c.Addresses)
  39. };
  40. }
Add Comment
Please, Sign In to add comment