Jereme
Jereme

Reputation: 1485

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.

Upvotes: 4

Views: 5290

Answers (1)

HiperiX
HiperiX

Reputation: 407

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.

Upvotes: 5

Related Questions