Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. select
  2. *
  3. from
  4. t1
  5. inner join
  6. t2
  7. on t1.codigo = t2.codigo
  8. and t1.versao = t2.versao;
  9.  
  10. public class T1Map : ClassMap<T1>{
  11. public T2Map() {
  12. Table("TB_WF_T1");
  13. Id(x => x.Codigo, "CD_T1").GeneratedBy.Sequence("SEQ_TB_WF_T1");
  14. Map(x => x.Versao, "CD_VERSAO");
  15. HasMany(x => x.T2).KeyColumn("FK_CODIGO_T1").LazyLoad().Inverse().Cascade.SaveUpdate();
  16. }
  17. }
  18.  
  19. public class T2Map : ClassMap<T2>{
  20. public T2Map() {
  21. Table("TB_WF_T2");
  22. Id(x => x.Codigo, "CD_T2").GeneratedBy.Sequence("SEQ_TB_WF_T2");
  23. Map(x => x.Versao, "CD_VERSAO");
  24. References(x => x.T1).Column("FK_CODIGO_T1").LazyLoad().Cascade.None();
  25. }
  26. }
  27.  
  28. public class MapEmpresaProduto : MapBase<EmpresaProduto>
  29. {
  30. public MapEmpresaProduto()
  31. {
  32. Table("EmpresaProduto");
  33. CompositeId()
  34. .KeyReference(x => x.Empresa, "IdEmpresa")
  35. .KeyReference(x => x.Produto, "IdProduto");
  36.  
  37. References(x => x.Empresa)
  38. .Not.Nullable()
  39. .Fetch.Join()
  40. .Cascade.SaveUpdate()
  41. .Column("IdEmpresa")
  42. .ReadOnly();
  43.  
  44. References(x => x.Produto)
  45. .Not.Nullable()
  46. .Fetch.Join()
  47. .Cascade.SaveUpdate()
  48. .Column("IdProduto")
  49. .ReadOnly();
  50. }
  51. }
  52.  
  53. public class EmpresaProduto : EntidadeAuditavelSemId
  54. {
  55. public virtual Produto Produto { get; set; }
  56.  
  57. public virtual Empresa Empresa { get; set; }
  58.  
  59. protected EmpresaProduto()
  60. {
  61. }
  62.  
  63. public EmpresaProduto(Empresa empresa, Produto produto) : this()
  64. {
  65. Produto = produto;
  66. Empresa = empresa;
  67. }
  68.  
  69. public override bool Equals(object entity)
  70. {
  71. if (entity == null || !(entity is EmpresaProduto))
  72. {
  73. return false;
  74. }
  75.  
  76. // Mesmas instâncias devem ser consideradas iguais
  77. if (ReferenceEquals(this, entity))
  78. {
  79. return true;
  80. }
  81.  
  82. // Objetos transientes não são considerados iguais
  83. var other = (EmpresaProduto)entity;
  84. var typeOfThis = GetType();
  85. var typeOfOther = other.GetType();
  86. if (!typeOfThis.IsAssignableFrom(typeOfOther) && !typeOfOther.IsAssignableFrom(typeOfThis))
  87. {
  88. return false;
  89. }
  90.  
  91. return Produto.Id.Equals(other.Produto.Id) && Empresa.Id.Equals(other.Empresa.Id);
  92. }
  93.  
  94. public override int GetHashCode()
  95. {
  96. unchecked
  97. {
  98. var hash = GetType().GetHashCode();
  99. hash = (hash * 31) ^ Produto.GetHashCode();
  100. hash = (hash * 31) ^ Empresa.GetHashCode();
  101.  
  102. return hash;
  103. }
  104. }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement