Fluent NHibernate - How to map the foreign key column as a property
Posted
by Steve
on Stack Overflow
See other posts from Stack Overflow
or by Steve
Published on 2009-04-01T23:16:39Z
Indexed on
2010/04/17
8:43 UTC
Read the original article
Hit count: 241
nhibernate
|fluent-nhibernate
I am sure this is a straightforward question but consider the following: I have a reference between company and sector as follows:
public class Company {
public Guid ID { get; set; }
public Sector Sector { get; set; }
public Guid SectorID { get; set; }
}
public class Sector {
public Guid ID { get; set; }
public string Name { get; set; }
}
Ok. What I want is the SectorID of the Company object to be populated after I go: (new Company()).Sector = new Sector() { Name="asdf" } and do a flush.
The mapping I am using kindly creates an additional column in the database called Sector_Id in the Company table, but this is not available as a property on Company. I want the SectorID property to be filled.
The mapping i am currently using in the CompanyMap is References(c => c.Sector).Cascade.All();
Does anyone have any ideas?
© Stack Overflow or respective owner