存储架构

Automapping has no mapped ID

微信扫一扫,分享到朋友圈

Automapping has no mapped ID
0
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

阅读原文...


微信扫一扫,分享到朋友圈

Automapping has no mapped ID
0

Hello, buddy!

Qualcomm: First 5G phones could arrive in 2018 with up to 4Gbps speeds

上一篇

The Brotherhood of the Ad Blockers

下一篇

评论已经被关闭。

插入图片

热门分类

往期推荐

Automapping has no mapped ID

长按储存图像,分享给朋友