I am working with brownfield database that uses strings as primary keys.
Using Fluent NHibernate with Sqlite (in-memory provider for unit testing) and SQL Server 2005.
I have the following entity:
public class Entity
{
public virtual DateTime TimeStamp { get; set; }
public virtual string Name { get; set; }
}
With this mapping:
public class EntityMap : ClassMap<Entity>
{
public EntityMap()
{
Map(_ => _.TimeStamp);
Id(_ => _.Name).CustomType("AnsiString");
}
}
However it does not work saying NHibernate.TypeMismatchException : Provided id of the wrong type. Expected: System.Int32, got System.String
How make this work? Also, is there any good documentation about fluent nhibernate available?
Thanks in advance.
If you are using strings as your primary keys you’ll probably have to do something like this:
From the nhibernate documentation:
Also here is a related article. It is a bit dated but still applies to your situation:
http://groups.google.com/group/fluent-nhibernate/browse_thread/thread/6c9620b7c5bb7ca8