Guest User

Untitled

a guest
Jan 22nd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. public abstract partial class AlertSpecification
  2. {
  3. private long _alertSpecificationId;
  4. private string _specificationName;
  5. private bool _active;
  6. private int _createdBy;
  7. private DateTime _createdOn;
  8.  
  9. public virtual long AlertSpecificationId
  10. {
  11. get { return _alertSpecificationId; }
  12. set { _alertSpecificationId = value; }
  13. }
  14.  
  15. public virtual string SpecificationName
  16. {
  17. get { return _specificationName; }
  18. set { _specificationName = value; }
  19. }
  20.  
  21. public virtual bool Active
  22. {
  23. get { return _active; }
  24. set { _active = value; }
  25. }
  26.  
  27. public virtual int CreatedBy
  28. {
  29. get { return _createdBy; }
  30. set { _createdBy = value; }
  31. }
  32.  
  33. public virtual DateTime CreatedOn
  34. {
  35. get { return _createdOn; }
  36. set { _createdOn = value; }
  37. }
  38. }
  39.  
  40. public partial class ComponentSpecification : AlertSpecification
  41. {
  42. private string _vehicleType;
  43.  
  44. public virtual string VehicleType
  45. {
  46. get { return _vehicleType; }
  47. set { _vehicleType = value; }
  48. }
  49. }
  50.  
  51. public partial class ColdVehicleSpecification : AlertSpecification
  52. {
  53. private double _sigmaThreshold;
  54.  
  55. public virtual double SigmaThreshold
  56. {
  57. get { return _sigmaThreshold; }
  58. set { _sigmaThreshold = value; }
  59. }
  60. }
  61.  
  62. <?xml version="1.0" encoding="utf-8"?>
  63. <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
  64.  
  65. namespace="IS.QueryPerformanceTest.Model" assembly="IS.QueryPerformanceTest.Model" >
  66. <class name="AlertSpecification" abstract="true">
  67. <cache usage="read-write"/>
  68. <id name="AlertSpecificationId" type="Int64">
  69. <generator class="hilo"/>
  70. </id>
  71. <property name="SpecificationName" column="Name" />
  72. <property name="Active" />
  73. <property name="CreatedBy" />
  74. <property name="CreatedOn" />
  75. <union-subclass name="ColdVehicleSpecification" table="AlertSpecificationColdVehicle">
  76. <property name="SigmaThreshold" column="CVSigmaThreshold" />
  77. </union-subclass>
  78. <union-subclass name="ComponentSpecification" table="AlertSpecificationComponent">
  79. <property name="VehicleType" column="VehicleType" />
  80. </union-subclass>
  81. </class>
  82. </hibernate-mapping>
  83.  
  84. var repo = new NHComponentSpecificationRepository(ObjectFactory.GetInstance<ISession>
  85.  
  86. ());
  87.  
  88. var cvRepo = new
  89.  
  90. NHColdVehicleSpecificationRepository(ObjectFactory.GetInstance<ISession>());
  91.  
  92. var allComponentSpecs = repo.FindAll();
  93. var allColdVehicleSpecs = cvRepo.FindAll();
  94.  
  95. public IList<ColdVehicleSpecification> FindAll()
  96. {
  97. var result = _session.Query<ColdVehicleSpecification>().ToList();
  98.  
  99. return result;
  100. }
  101.  
  102. ComponentSpecification cs = new ComponentSpecification ();
  103. session.Store(cs);
  104. var csId = cs.Id;
  105.  
  106. // later on,
  107. // crashes with a cast exception
  108. var cvs = session.Get<ColdVehicleSpecification>(csId);
Add Comment
Please, Sign In to add comment