Can someone help me with the best way to match the following situation with the current nHibernate? The Address class is used both in the client and in the company. How can I store it most efficiently in SQL? And what should the comparison look like? I thought of several options, but I'm not experienced enough with nHibernate for these situations:
use 1 address entity and 1 table and use the denominator column to distinguish between the address for the client and the address for the company β how to implement this in nHibernate?
use 1 address entity and 2 tables (ClientAddresses and CompanyAddresses) β but I can only define 1 table when matching the Address class
use 2 addresses and 2 tables -> not very elegant
I just stumbled upon this problem when I started implementing a company class and realized that it also needed several addresses. So far, I had the Address and Client class, and there was one, many things between them. In the database, the address had an additional column CustomerId. But introducing the company class, I was stuck ...
Any help would be greatly appreciated.
I am currently working in the area of ββsharparch 1.5, which uses automation, and my mapping files look like this:
public class AddressMap : IAutoMappingOverride<Address> { public void Override(AutoMapping<Address> mapping) { mapping.Table("addresses"); mapping.Id(x => x.Id, "AddressGuid") .UnsavedValue(Guid.Empty) .GeneratedBy.GuidComb(); mapping.References(x => x.Client, "ClientGuid"); } }
Below is another code illustrating the problem:
Address
public class Address { public virtual string StreetLine1 { get; set; } public virtual string StreetLine2 { get; set; } public virtual string PostalCode { get; set; } public virtual string City { get; set; } public virtual string Country { get; set; } }
which has the following table:
tablename = addresses
fields = AddressGuid, StreetLine1, StreetLine2, PostalCode, City, Country
Client
public class Client { public IList<Address> Addresses {get;set;} }
Company
public class Company { public IList<Address> Addresses {get;set;} }