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!阅读原文】。感谢您的支持!


JAVAEE——宜立方商城07:Linux上搭建Solr服务、数据库导入索引库、搜索功能的实现... 1.学习计划 1、Solr 服务搭建 2、Solrj 使用测试 3、把数据库中的数据导入索引库 4、搜索功能的实现 2. Solr 服务搭建 2.1. Solr 的环境 Solr 是 jav...
1.NetDh框架之数据库操作层–Dapper简单封装,可支持多库实例、多种数据库类型等... 1.NetDh框架开始的需求场景 需求场景: 1.之前公司有不同.net项目组,有的项目是用SqlServer做数据库,有的项目是用Oracle,后面也有可能会用到Mysql等,而且要考虑后续扩展成主从库、多库的需求。( ...
Go基础学习记录之如何在Golang中使用Session... Session背后的基本原则是服务器维护每个客户端的信息,客户端依赖唯一的SessionID来访问此信息。 当用户访问Web应用程序时,服务器将根据需要使用以下三个步骤创建新Session: 创建唯一的Sessio...
ArangoDB 3.3.16 发布,原生多模数据库 ArangoDB 3.3.16 发布,原生多模数据库 ArangoDB 3.3.16 发布了,ArangoDB 是一个原生的多模型数据库,具有灵活的文档、图形和键值数据模型。使用方便的 SQL 查询语言或 JavaScript ...
College Student needs help resolving php/database ... Hi, so I'm new to PHP, and I'm taking a college class on it. However the instructor is not particularly helpful with his...