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! (源链)。感谢您的支持!


70后.net老猿,尚能饭否? 程序猿的大限 距离上一次主动找工作,快到5年了,到现在的东家,是差不多3年前猎头挖过来的,而当时东家刚刚被欧洲一家有百年历史的跨国企业集团收购,所以我也就有...
Do we need specialized graph databases? Benchmarki... Do we need specialized graph databases? Benchmarking real-time social networkin...
移动商城第三篇(商品管理)【查询商品、添加商品】... 逆向生成item 将表名设置成eb_item就行了。 查询商品 由于我们查询商品的话,可能商品的数量是非常大...
How to create REST APIs using aiohttp aiohttp is HTTP client/server for python and AsyncIO . It supports both server ...
Demoing Latch Waits with Stupid Tricks Say you’ve got PAGELATCH_UP or PAGELATCH_EX waits, and you’re wondering what ...