views:

252

answers:

0

Hi,

I'm observing some strange behavior whilst trying to perform a query on an NHibernate entity. The primary key of my object is a string (guid), but when I pass in the guid string I wish to query by, I get an exception,

NHibernate.ADOException: could not execute query System.FormatException: Input string '6eaa591f-bb75-4c0b-8acb-fb12ea0a74d5' was not in the correct format. ---> System.FormatException: Input string was not in a correct format.

And when I look at the generated sql it shows me this,

select * from ( SELECT this_.FOLDER_ID as FOLDER1_5_0_, this_.FOLDER_LABEL as FOLDER5_5_0_, this_.PARENT_ID as PARENT7_5_0_ FROM FOLDER this_ WHERE this_.FOLDER_ID = :p0 ) where rownum <=:p1 ] Positional parameters: #0>ae6b2094-c4f7-4c2e-a2b1-4e256d53fe5a

My mapping class looks like this,

public class FolderMap : ClassMap<Folder>
{
    public FolderMap()
    {
        Table("FOLDER");

        Id(x => x.Id, "FOLDER_ID");
        Map(x => x.FolderLabel, "FOLDER_LABEL");
        Map(x => x.ParentId, "PARENT_ID");
    }
}

And the query I'm trying to execute is written like so,

   string id = "ae6b2094-c4f7-4c2e-a2b1-4e256d53fe5a";

   var folderRecord = session.Linq<Folder>().FirstOrDefault(f => f.Id == id);

So what I'm gathering here is that NHibernate is trying to convert my guid string into a number on the way through, but here's the really interesting part, if I query for just a plane test string, say like this,

   string id = "TEST";

   var folderRecord = session.Linq<Folder>().FirstOrDefault(f => f.Id == id);

The query executes no problems. Has anyone else experienced anything like this?

Thanks in advance.

Matt