4

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.

Vadim
  • 17,897
  • 4
  • 38
  • 62
Jereme
  • 1,445
  • 1
  • 16
  • 32
  • In your connection string, *try* adding "BinaryGuid=False". I emphasize "try" because I'm not 100% sure on this solution. Hence the comment vs answer. – mxmissile Feb 14 '11 at 17:00
  • 1
    @Jereme are you sure `Photo` is the entity causing the problem? – Diego Mijelshon Feb 14 '11 at 17:03
  • @mxmissile - That didn't work. Maybe I'll just put a key string in the Photo class and use an int so I don't have to use Guid. Though that sounds crappy :( – Jereme Feb 14 '11 at 23:42
  • @Diego yes, I pulled every other Guid from my models. – Jereme Feb 14 '11 at 23:43
  • @Jereme I don't think using a Guid is the problem. We'll need to see more. – Diego Mijelshon Feb 14 '11 at 23:59
  • I've decided to go a different direction for now and come back to this later. Thanks for the suggestions. – Jereme Feb 16 '11 at 18:37
  • Off-topic: In most RDBMS using a GUID for a primary key is usually a less-than-optimal solution. See http://www.sqlskills.com/BLOGS/KIMBERLY/post/GUIDs-as-PRIMARY-KEYs-andor-the-clustering-key.aspx – Jon Adams Feb 26 '11 at 17:06
  • Was there an inner exception? If yes, what did it say? – Anders Feb 27 '11 at 20:34

1 Answers1

5

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.

Community
  • 1
  • 1
HiperiX
  • 395
  • 5
  • 19
  • Actually, yes... @least according to http://nhforge.org/blogs/nhibernate/archive/2009/05/21/using-the-guid-comb-identifier-strategy.aspx ; but there is a performance impact (specially if you're inserting lots of rows). On the other hand, I don't know if current Fluent NH supports guid.comb as an index strategy (I'm almost 99% certain that the 1.0 version did not). – HiperiX Dec 13 '12 at 17:39
  • 1
    I have this in my mapping: `Id(x => x.Id).GeneratedBy.GuidComb();` (FNH 1.3.0.733) and it seems to work fine. – user1068352 Dec 13 '12 at 21:06