NHibernate: How to map a column on a referenced table to a primitive in my object? -
If I have an existing table schema
+ ------- - ----------- + ------------------- + | Address | Country | + ------------------- + + ------------------- + | Line 1 | + --- & gt; | Country ID | | Line 2 | | | Name | | City | | + ------------------- + | State | | | ZIP | | | CountryID | --- + + ------------------- + ... and my class is as follows
< Former> ... How can I configure my mapping so that country [string] property contains the [Name] column Join [country] table
You can get it by mapping Are opinions But object-oriented approach will be to create a country object and map multiple relationships between address and country:
public class address {public virtual string line 1 {get; Set; } Public Virtual String Line2 {get; Set; } Public virtual string city {get; Set; } Public virtual string state {get; Set; } Public virtual string postal code (get); Set; } Public virtual country country {get; Set; }} You will then use the name through the name. country name. In FluentNHibernate you will use to mapping the relationship in your address mapping: context (x => x country; country id);
Comments
Post a Comment