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()
                        .Database(DatabaseConfigurer)
                        .Mappings(m=>m.AutoMappings.Add(model));

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);
    }

    #endregion
}

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

for further info on overriding, see http://wiki.fluentnhibernate.org/Auto_mapping#Overrides
.

Cheers,

Jhonny

Hello, buddy!

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

您可能感兴趣的

秋招规律与经验总结 西安地区的秋季招聘已接近尾声,我也终于找到了自己理想的工作,都说一篇总结性的文章是对上一阶段最好的回顾,那么我就用这一篇文章为秋季招聘画上一个完美的句号。 三个规律 希望你能在秋季招聘之前或者正在进行的时候看到这部分内容。 下面介绍的三个规律与我的人生经历与体验密切相关,尽管...
NodeJs之数据库异常处理 数据库异常 NodeJs版本:4.4.4 数据库链接错误 使用nodejs处理异常最麻烦不过,这里我抛开nodejs提供的 domain 和一些第三方库专门处理的东西。操作数据库是我们常用的功能。通过回调,我们这里会有很多err出没。 如下: var pool = r...
PostGIS – Importing Spatial Data Once you have PostgreSQL set up with the PostGIS extension, you are probably keen to perform some spatial queries against some real world data. You ...
用node实现一个简单的聊天室—— 升级版... 在上一篇文章中, 我们用egg实现了基本的聊天室功能, 本章我们在其基础上进行一个小升级, 添加用户登录、注册的功能, 添加查询聊天室成员的功能。在本章中, 通过token来进行用户识别, 通过mysql来保存用户信息, 将会用到egg的对应插件。 前端部分 效果图 ...
Hyperion EPMA Way For developers in Hyperion community, choosing between Classic Vs EPMA approach has been a vital one. This blog gives a brief insight to EPMA app...