Open siphomaribo opened 1 year ago
I'm also facing the same issue. Any solution on this?
Foremost, this is not an issue of FluentNHibernate. FluentNHibernate can only create the configuration and mapping for NHibernate.
Your case is a common behavior of NHibernate.
The example code never assigns any value to the property of Company.Accountant
or to the Accountant.Companies
. Therefor the property is null
. And the database reflects this model state.
If you make your Company.Accountant
reference the correct Accountant
model, it will do so in the DB as well.
Try something like:
public void Create_Accountant()
{
var repo = new Repository();
var companies = new List<Company>();
companies.Add(repo.GetById<Company>(new Guid("02032BD9-2769-4183-9750-AF1F00A5E191")));
companies.Add(repo.GetById<Company>(new Guid("F86E8B40-73D2-447E-A525-AF1F00A5E191")));
var accountant = new Accountant
{
Name = "Accountant Simba",
Companies = companies,
};
foreach (var item in companies)
{
item.Accountant = accountant;
}
repo.Save(accountant);
}
I am struggling to have the Foreign Keys in my mappings.
My Model looks like this:
and my Mappings look like this
here's how my Save method looks like
After the code has executed, this is what in my Database
You'd notice that the Account_id column is empty and it should not be empty.
Someone, please help me, what am I doing wrong?