The map.
public SocialCodeMap()
{
Id(x => x.SocialCodeId);
Map(x => x.Name);
Map(x => x.Code);
Map(x => x.DisplayOrder);
}
And the Class.
public class SocialCode
{
public virtual Guid SocialCodeId { get; set; }
public virtual string Name { get; set; }
public virtual char Code { get; set; }
public virtual int DisplayOrder { get; set; }
}
And the call.
public SocialCode FetchByCode(char code)
{
return Session.CreateCriteria<SocialCode>().Add<SocialCode>(x => x.Code == code).UniqueResult<SocialCode>();
}
I receive this error when running FetchByCode().
System.Exception: Cannot convert '65' to System.Char
at NHibernate.LambdaExtensions.ExpressionProcessor.ConvertType(Object value, Type type)
at NHibernate.LambdaExtensions.ExpressionProcessor.ProcessSimpleExpression(BinaryExpression be)
at NHibernate.LambdaExtensions.ExpressionProcessor.ProcessBinaryExpression(BinaryExpression expression)
at NHibernate.LambdaExtensions.ExpressionProcessor.ProcessLambdaExpression(LambdaExpression expression)
at NHibernate.LambdaExtensions.ExpressionProcessor.ProcessExpression<T>(Expression`1 expression)
at NHibernate.LambdaExtensions.ICriteriaExtensions.Add<T>(ICriteria criteria, Expression`1 expression)
at DAL.NHibernate.xxx.SocialCodeRepository.FetchByCode(Char code) in SocialCodeRepository.cs: line 18
at UnitTests.DAL.xxx.yyy.SocialCodeRepositoryFixture.FetchByCode_ReturnsNullCodeDNE() in SocialCodeRepositoryFixture.cs: line 38
It seems NHibernate is convering my char to an int somewhere along the way. How can I force it to use the char(1) type that is on the column?