<join> is for when you want to put data from multiple tables into a _single_ object. (Since it is a single object, the same primary key is used in both tables.) The model in your picture shows two classes. It seems like what you want is a regular many-to-one mapping from address to postcode. This can be set to eager load using a join in the SQL if you want.
But your CustomerAddress below contains both PostCode, PostCodeId, ZipCode and City.... so perhaps you need to clarify what you really want if the above doesn't help. Also, I find it somewhat weird that PostCode should have a collection of adresses. Maybe it works for you - but in general, since the postcode doesn't actually own the adresses, and also since its adress collection could get very large, I would avoid that kind of construction. /Oskar 2011/9/13 DobrocsiGergely <[email protected]>: > Hi All! > > I would like to ask some help about joining two entities. > > Here is my model (Address & PostCode): http://www.dobrosoft.hu/nh/address.jpg > > ________________________________________ > And here is a mapping of custom class: > > [System.CodeDom.Compiler.GeneratedCode("NHibernateModelGenerator", > "1.0.0.0")] > [Serializable] > public partial class CustomAddress > { > [Required] > public virtual long Id { get; set; } > [Required] > [Length(100)] > public virtual string Street { get; set; } > [Length(10)] > public virtual string Number { get; set; } > public virtual System.Nullable<int> Serial { get; set; } > > public virtual CustomDictionaryItem AddressType { get; set; } > > public virtual long OrganizationId { get; set; } > public virtual long UserId { get; set; } > > public virtual CustomPostCode PostCode { get; set; } > public virtual long PostCodeId { get; set; } > public virtual string Zipcode { get; set; } > public virtual string City { get; set; } > public virtual CustomDictionaryItem Country { get; set; } > public virtual CustomDictionaryItem County { get; set; } > > static partial void > CustomizeMappingDocument(System.Xml.Linq.XDocument mappingDocument); > > internal static System.Xml.Linq.XDocument MappingXml > { > get > { > var mappingDocument = > System.Xml.Linq.XDocument.Parse(@"<?xml version='1.0' > encoding='utf-8' ?> > <hibernate-mapping xmlns='urn:nhibernate-mapping-2.2' > assembly='" + > typeof(CustomAddress).Assembly.GetName().Name + @"' > namespace='OnFlow' > > > <class name='CustomAddress' > table='`address`' > dynamic-update='true' > dynamic-insert='true' > > > <id name='Id' > column='`Id`' > > > <generator class='hilo'> > <param name='table'>globalid</param> > <param name='column'>Id</param> > <param name='max_lo'>0</param> > </generator> > </id> > <property name='Street' > column='`Street`' > /> > <property name='Number' > column='`Number`' > /> > <property name='Serial' > column='`Serial`' > /> > <property name='OrganizationId' > column='`OrganizationId`' > /> > <property name='UserId' > column='`UserId`' > /> > > <many-to-one name='AddressType' class='CustomDictionaryItem' > column='`AddressTypeId`' fetch='join' not-found='ignore'/> > <join table='postcode'> > <key column='Id' property-ref='PostCodeId'/> > <property name='Zipcode'/> > <property name='City'/> > <many-to-one name='Country' class='CustomDictionaryItem' > column='`CountryId`' fetch='join' not-found='ignore'/> > <many-to-one name='County' class='CustomDictionaryItem' > column='`CountyId`' fetch='join' not-found='ignore'/> > </join> > </class> > </hibernate-mapping>"); > CustomizeMappingDocument(mappingDocument); > return mappingDocument; > } > } > } > > ________________________________________ > > When I use this, the generated sql is that: > > …. > FROM address this_ > inner join postcode this_1_ on this_. Id = this_1_.Id > …. > > ________________________________________ > Unfortunatelly that’s no good, because this_.PostCodeId = this_1_.id > would be the correct! > > Could you help me? > > -- > You received this message because you are subscribed to the Google Groups > "nhusers" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/nhusers?hl=en. > > -- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
