流畅的nhibernate问题映射char(1)类型
地图。
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) 类型?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设 Fluent-NH 可以自动正确检测字符类型。但如果不能,您可以随时向其显示提示。尝试此
更新:
抱歉,我还没有测试代码。我尝试了一下,发现错误出在 NH Lambda Extensions 中。简而言之,
我测试过这应该可行。
I assume Fluent-NH can automatically detect char type correctly. But if it can't, you can always show a hint to it. Try this
Update:
Sorry that I haven't tested the code. Well I tried and found that the bug is in NH Lambda Extensions. In short,
I tested this should work.