Im fairly n00bish when it comes to fluent nhibernate but i have an unexpected error in one of my repositories.
I have a datatype CostCode
public class CostCode
{
public virtual int Id { get; set; }
public virtual String CostCodeCode { get; set; }
public virtual Company Company { get; set; }
public virtual DateTime CreatedDate { get; set; }
public virtual String CreatedBy { get; set; }
public virtual DateTime ModifiedDate { get; set; }
public virtual String ModifiedBy { get; set; }
}
and here is the mapping
public sealed class CostCodeMap : ClassMap<CostCode>
{
/**
* @breif Mapping Constructor
*/
public CostCodeMap()
{
Id(Reveal.Member<CostCode>("Id"));
Map(x => x.CostCodeCode).Not.Nullable();
References(x => x.Company, "CompanyId").Cascade.All();
Map(x => x.CreatedDate).Not.Nullable();
Map(x => x.CreatedBy).Not.Nullable();
Map(x => x.ModifiedDate).Not.Nullable();
Map(x => x.ModifiedBy).Not.Nullable();
}
}
When i try to update this, i get an error "identifier of an instance of Domain.DataTypes.Company was altered from 1 to 8"
Now i think its the way that i set up the mapping, and possibly how my repository is handling the updates/adds.
I have a drop down list that controls the id of the company, and when im adding/updating i set the property company to whatever is in the database for the id that it has been updated to.
var companyRepository= new CompanyRepository(_session);
temp.Company = companyRepository.GetCompanyById(temp.Company.Id);
_session.Update(c);
Can anyone give me a hint/solution to help me on my way? Looking through related problems here, the problem could be anything.