Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. private int _id;
  2. private string _name;
  3. private IList<Location> _subLocations;
  4. private IList<Stock> _stockList;
  5. private Location _parent;
  6. private bool _isActive;
  7. private bool _recommend;
  8.  
  9. public virtual IList<Location> SubLocations
  10. {
  11. get
  12. {
  13. if (_subLocations == null)
  14. {
  15. _subLocations = new List<Location>();
  16. }
  17.  
  18. return _subLocations;
  19. }
  20. set
  21. {
  22. _subLocations = value;
  23. OnPropertyChanged("SubLocations");
  24. }
  25. }
  26.  
  27. // more properties ...
  28.  
  29. public class LocationMap:ClassMap<Location>
  30. {
  31. public LocationMap()
  32. {
  33. Id(x => x.Id);
  34. Map(x => x.Name);
  35. Map(x => x.IsActive);
  36. References(x => x.Parent);
  37.  
  38. HasMany(x => x.SubLocations).Where(x => x.IsActive == true);
  39. HasMany(x => x.StockList).Where(x => x.IsActive == true);
  40.  
  41. Table("tbl_locations");
  42.  
  43. }
  44. }
  45.  
  46. Id Name IsActive Parent_id
  47. 1 Magazijn A 1 NULL
  48. 2 Magazijn B 1 NULL
  49. 3 Gang A 1 2
  50. 4 Rek B 1 3
  51.  
  52. public IList<Location> GetAllParentLocations()
  53. {
  54. var result = NHibernateHelper.Session.CreateQuery("from Location l fetch all properties where l.Parent is null and l.IsActive = true").List<Location>();
  55. return (List<Location>)result ?? new List<Location>();
  56. }
  57.  
  58. NHibernate: select location0_.Id as Id15_, location0_.Name as Name15_, location0_.IsActive as IsActive15_, location0_.Parent_id as Parent4_15_ from tbl_locations location0_ where (location0_.Parent_id is null) and location0_.IsActive=1
  59. NHibernate: SELECT sublocatio0_.Location_id as Location5_1_, sublocatio0_.Id as Id1_, sublocatio0_.Id as Id15_0_, sublocatio0_.Name as Name15_0_, sublocatio0_.IsActive as IsActive15_0_, sublocatio0_.Parent_id as Parent4_15_0_ FROM tbl_locations sublocatio0_ WHERE (sublocatio0_.IsActive = 1) and sublocatio0_.Location_id=@p0;@p0 = 1 [Type: Int32 (0)]
  60. NHibernate: SELECT sublocatio0_.Location_id as Location5_1_, sublocatio0_.Id as Id1_, sublocatio0_.Id as Id15_0_, sublocatio0_.Name as Name15_0_, sublocatio0_.IsActive as IsActive15_0_, sublocatio0_.Parent_id as Parent4_15_0_ FROM tbl_locations sublocatio0_ WHERE (sublocatio0_.IsActive = 1) and sublocatio0_.Location_id=@p0;@p0 = 42 [Type: Int32 (0)]
  61. NHibernate: SELECT sublocatio0_.Location_id as Location5_1_, sublocatio0_.Id as Id1_, sublocatio0_.Id as Id15_0_, sublocatio0_.Name as Name15_0_, sublocatio0_.IsActive as IsActive15_0_, sublocatio0_.Parent_id as Parent4_15_0_ FROM tbl_locations sublocatio0_ WHERE (sublocatio0_.IsActive = 1) and sublocatio0_.Location_id=@p0;@p0 = 60 [Type: Int32 (0)]
  62.  
  63. HasMany(x => x.SubLocations).KeyColumns.Add("Parent_Id").Where(x => x.IsActive == true);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement