简体   繁体   中英

Fluent NHibernate Guid Mapping is failing

I'm seeing the following error with my Fluent NHibernate map:

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. 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. It does not scale well (GUID is a non-sortable type) that can lead to high index fragmentation on your database.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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