简体   繁体   English

流畅的NHibernate Guid Mapping失败了

[英]Fluent NHibernate Guid Mapping is failing

I'm seeing the following error with my Fluent NHibernate map: 我在Fluent NHibernate地图上看到以下错误:

NHibernate.MappingException: Association references unmapped class: System.Guid

I swear I've done this before and it's worked, so I'm not sure what's causing the problem. 我发誓以前我已经做过这件事并且有效,所以我不确定是什么导致了这个问题。 I'm using FNH 1.1 with a SQLite database. 我正在使用FNH 1.1和SQLite数据库。 Here is my class and map: 这是我的班级和地图:

public class Photo
{
    public virtual Guid Id { get; set; }
    public virtual byte[] Data { get; set; }
    public virtual string Caption { get; set; }
}


public class PhotoMap : ClassMap<Photo>
{
    public PhotoMap()
    {
        Id(p => p.Id).GeneratedBy.Guid();
        Map(p => p.Caption);
        Map(p => p.Data);
    }
}

Thanks for the help. 谢谢您的帮助。

Try to not use GUID as the entity primary key. 尽量不要使用GUID作为实体主键。 It does not scale well (GUID is a non-sortable type) that can lead to high index fragmentation on your database. 它不能很好地扩展(GUID是一种不可排序的类型),可能导致数据库上的高索引碎片。

Failing that, see Issue With Fluent Nhibernate Automapping and Guids / UniqueIdentifiers as Primary Key Fields - this notes that the 1.0 version of FluentNH has a bug handling GUIDs as IDs, and suggests to use the SVN Trunk. 如果不这样做,请参阅Fluent Nhibernate Automapping和Guids / UniqueIdentifiers作为主键字段的问题 - 这表明1.0版本的FluentNH有一个错误处理GUID作为ID,并建议使用SVN中继。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM