Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- select
- *
- from
- t1
- inner join
- t2
- on t1.codigo = t2.codigo
- and t1.versao = t2.versao;
- public class T1Map : ClassMap<T1>{
- public T2Map() {
- Table("TB_WF_T1");
- Id(x => x.Codigo, "CD_T1").GeneratedBy.Sequence("SEQ_TB_WF_T1");
- Map(x => x.Versao, "CD_VERSAO");
- HasMany(x => x.T2).KeyColumn("FK_CODIGO_T1").LazyLoad().Inverse().Cascade.SaveUpdate();
- }
- }
- public class T2Map : ClassMap<T2>{
- public T2Map() {
- Table("TB_WF_T2");
- Id(x => x.Codigo, "CD_T2").GeneratedBy.Sequence("SEQ_TB_WF_T2");
- Map(x => x.Versao, "CD_VERSAO");
- References(x => x.T1).Column("FK_CODIGO_T1").LazyLoad().Cascade.None();
- }
- }
- public class MapEmpresaProduto : MapBase<EmpresaProduto>
- {
- public MapEmpresaProduto()
- {
- Table("EmpresaProduto");
- CompositeId()
- .KeyReference(x => x.Empresa, "IdEmpresa")
- .KeyReference(x => x.Produto, "IdProduto");
- References(x => x.Empresa)
- .Not.Nullable()
- .Fetch.Join()
- .Cascade.SaveUpdate()
- .Column("IdEmpresa")
- .ReadOnly();
- References(x => x.Produto)
- .Not.Nullable()
- .Fetch.Join()
- .Cascade.SaveUpdate()
- .Column("IdProduto")
- .ReadOnly();
- }
- }
- public class EmpresaProduto : EntidadeAuditavelSemId
- {
- public virtual Produto Produto { get; set; }
- public virtual Empresa Empresa { get; set; }
- protected EmpresaProduto()
- {
- }
- public EmpresaProduto(Empresa empresa, Produto produto) : this()
- {
- Produto = produto;
- Empresa = empresa;
- }
- public override bool Equals(object entity)
- {
- if (entity == null || !(entity is EmpresaProduto))
- {
- return false;
- }
- // Mesmas instâncias devem ser consideradas iguais
- if (ReferenceEquals(this, entity))
- {
- return true;
- }
- // Objetos transientes não são considerados iguais
- var other = (EmpresaProduto)entity;
- var typeOfThis = GetType();
- var typeOfOther = other.GetType();
- if (!typeOfThis.IsAssignableFrom(typeOfOther) && !typeOfOther.IsAssignableFrom(typeOfThis))
- {
- return false;
- }
- return Produto.Id.Equals(other.Produto.Id) && Empresa.Id.Equals(other.Empresa.Id);
- }
- public override int GetHashCode()
- {
- unchecked
- {
- var hash = GetType().GetHashCode();
- hash = (hash * 31) ^ Produto.GetHashCode();
- hash = (hash * 31) ^ Empresa.GetHashCode();
- return hash;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement