I am having difficulty in composing primary key mapping using fluent nhibernate. I have the following class:
public class NotaItem
{
public NotaItem(){}
public virtual int Id { get; set; } //chave primaria
public virtual Int16 NumeroSequencialItem { get; set; } //chave primaria
public virtual Int16 NumeroOrdem { get; set; }
}
Mapping:
public class NotaItemMap : ClassMap<NotaItem>
{
public NotaItemMap()
{
Table("NOTITEM");
//Chave primária
CompositeId().KeyReference(x => x.Id, "NOTIT_ID")
.KeyProperty(x => x.NumeroSequencialItem, "NOTIT_NR_SEQUENCIAL_ITEM");
Map(x => x.NumeroOrdem)
.Column("NOTIT_NR_ORDEM")
.Not.Nullable();
}
}
I'd like to know the best way to do this implementation, because that way it's not working. Note: The primary key fields is not auto increment.
Exception Log: Exception:
FluentNHibernate.Cfg.FluentConfigurationException: An invalid or was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
---> FluentNHibernate.Cfg.FluentConfigurationException: An invalid or was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
---> NHibernate.MappingException: Could not compile the mapping document: (XmlDocument) --- > NHibernate.MappingException: composite-id class must override Equals (): TrainingNHibernate.Core.Entity.NoteItem in NHibernate.Cfg.XmlHbmBinding.ClassCompositeIdBinder.CheckEqualsAndGetHashCodeOverride () in NHibernate.Cfg.XmlHbmBinding.ClassCompositeIdBinder.BindCompositeId (HbmCompositeId idSchema, PersistentClass rootClass) in NHibernate.Cfg.XmlHbmBinding.RootClassBinder.Bind (HbmClass classSchema, IDictionary
2 inheritedMetas) em NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.AddEntitiesMappings(HbmMapping mappingSchema, IDictionary
2 inheritedMetas) in NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.Bind (HbmMapping mappingSchema) in NHibernate.Cfg.Configuration.AddDeserializedMapping (HbmMapping mappingDocument, String documentFileName) --- End of crawl stack of internal exceptions --- in NHibernate.Cfg.Configuration.LogAndThrow (Exception exception) in NHibernate.Cfg.Configuration.AddDeserializedMapping (HbmMapping mappingDocument, String documentFileName) in NHibernate.Cfg.Configuration.ProcessMappingsQueue () in NHibernate.Cfg.Configuration.AddInputStream (Stream xmlInputStream, String name) in NHibernate.Cfg.Configuration.AddDocument (XmlDocument doc, String name) in NHibernate.Cfg.Configuration.AddDocument (XmlDocument doc) in FluentNHibernate.PersistenceModel.Configure (Configuration cfg) in FluentNHibernate.Cfg.MappingConfiguration.Apply (Configuration cfg)
in FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration ()
--- End of internal exception stack trace --- in FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration () in FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory () --- End of stack trace of internal exceptions --- in FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory () in TrainingNHibernate.Data.SessionFactory.SessionFactoryUtil..cctor () at E: \ VisualCSharp \ Projects \ TrainingNHibernate \ TrainingNHibernate.Data \ SessionFactory \ SessionFactoryUtil.cs: line 46