Automapping has no mapped ID

存储架构 2018-05-10 阅读原文

My Entity Class:
public class Building
        /// internal Id
        public virtual long Id { get; set; }

My Mapping:

var model = AutoMap.AssemblyOf()
                        .Setup(s => s.FindIdentity = p => p.Name == "Id")
                        .Where(t => t.Namespace == "SpikeAutoMappings");

var database = Fluently.Configure()

I need somebody to help me see what is wrong because I keep having this error when run unit test:

Initialization method TestProject1.MappingTestBase.TestInitialize threw exception. FluentNHibernate.Cfg.FluentConfigurationException:  FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.

 --->  FluentNHibernate.Visitors.ValidationException: The entity doesn't have an Id mapped. Use the Id method to map your identity property. For example: Id(x => x.Id)..

both answers above are right; unless you specify differently, the automapper assumes that you have an int Id field.

If your Id is long, the automapper might not recognize it correctly.

try defining a MappingOverride for your class(es), like so:

public class UserMappingOverride : IAutoMappingOverride
    #region IAutoMappingOverride Members

    public void Override(AutoMapping mapping)
        mapping.Id(u => u.Name);


the Id() function allows you to override the automapper's convention of what the ID field should be.

for further info on overriding, see



Hello, buddy!

责编内容by:Hello, buddy!阅读原文】。感谢您的支持!