2012-03-15 55 views
0

我有一个DateTime列这样的映射:NHibernate的Restrictions.Ge( “的ColumnName”,DateTime.Now)产生无效的SQL

... 
Map(x => x.Created).Column("CREATED") 
        .Access.Property() 
        .CustomType<DateTime>() 
        .CustomSqlType("datetime") 
        .Not.Nullable(); 
... 

在我的代码定义

outboxCriteria.Add(Restrictions.Eq("Created", startDate)); 

其中'startDate'是DateTime类型的。

当寻找在创建SQL我看到上述标准

... 
    and Created = 2/14/2012 12:00:00 AM 
... 

这是不正确的。我期望NHibernate创建

... 
    and Created = '2/14/2012 12:00:00 AM' 
... 

我也观察到与String类型相同的问题。

Map(x => x.ReceiverName).Column("UserName") 
         .CustomType("string") 
         .Access.Property() 
         .CustomSqlType("nvarchar(256)") 
         .Nullable() 
         .Length(256); 

生成的SQL不把字符串引号:的

... 
    and UserName = Paul 
... 

代替

... 
    and UserName = 'Paul' 
... 

映射工作得很好,除了这些问题。

我在做什么错了?

+0

如果删除'.CustomType ()',会发生什么? – Rippo 2012-03-15 16:52:21

+0

@Rippo相同的结果... – Andreas 2012-03-15 17:39:16

回答

1

指定.CustomSqlType("nvarchar(256)")Length()呈现为noop。字符串和日期时间也不是customeTypes/customSqlTypes。也许NHibernate被他们弄糊涂了。

删除除Map(x => x.ReceiverName).Column("UserName").Length(256)之外的全部。