我的 iSeries DB2 模式中有下表:
CREATE TABLE LATHAM1.SGINES1.LICVP010
(ID FOR COLUMN ID10 BIGINT NOT NULL PRIMARY KEY,
CompanyCode FOR COLUMN CONO10 CHARACTER (2) CCSID 37 NOT NULL,
CreateDate FOR COLUMN CDAT10 DATE not null);
以及表的以下映射:
public class OrderReferenceID
{
public virtual long ID { get; set; }
public virtual string CompanyName { get; set; }
public virtual DateTime CreationDate { get; set; }
}
public class OrderReferenceIDMap : ClassMap<OrderReferenceID>
{
public OrderReferenceIDMap()
{
Table("LICVP010");
Id(x => x.ID, "ID10")
.GeneratedBy.Native()
.Not.Nullable();
Map(x => x.CompanyName, "CONO10")
.Length(2)
.Not.Nullable();
Map(x => x.CreationDate, "CDAT10");
}
}
和以下代码:
ISessionFactory sessionFactory = CreateSessionFactory();
using (var session = sessionFactory.OpenSession())
{
OrderReferenceID newID = new OrderReferenceID { CompanyName = "LI", CreationDate = DateTime.Now.Date };
session.Save(newID);
session.Flush();
session.Close();
}
当我执行这个时,我得到一个错误:
A conversion error occurred.
由于从 CLR DateTime 到 DB2 Date 对象的转换,这似乎正在发生。
我怎样才能正确映射这个?