地图。
public SocialCodeMap()
{
Id(x => x.SocialCodeId);
Map(x => x.Name);
Map(x => x.Code);
Map(x => x.DisplayOrder);
}
和类。
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; }
}
和电话。
public SocialCode FetchByCode(char code)
{
return Session.CreateCriteria<SocialCode>().Add<SocialCode>(x => x.Code == code).UniqueResult<SocialCode>();
}
我在运行 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
似乎 NHibernate 正在将我的 char 转换为 int 。如何强制它使用列上的 char(1) 类型?