NHibernate的3指定与能说会道的语法SQL数据类型 [英] NHibernate 3 specify sql data type with loquacious syntax
问题描述
我想一个实体与字符串属性映射到NHibernate的3使用新的API贫嘴一个的 VARCHAR 的列,但我无法弄清楚如何指定要使用的类型。我能够正确映射与NHibernate 2和FluentNHibernate的实体。
NHibernate的2瓦特/流利的映射
公共类EntityMapping:ClassMap<实体GT;
{
公共EntityMapping()
{
表(EntityTable);
ID(X => x.EntityId)。.Column(ENTITYID)GeneratedBy.Identity();
地图(X => x.Code).Not.Nullable()列(EntityCode)CustomType(AnsiString类型)。;
}
}
NHibernate的3W /贫嘴API
公益行动< IClassMapper<实体GT;> CreateMapping()
{
返回CA =>
{
ca.Table(实体);
ca.Id(X => x.EntityId,地图= GT;
{
map.Column(ENTITYID);
map.Generator(Generators.Identity) ;
});
ca.Property(X => x.Code,地图= GT;
{
map.Column(厘米=> {
cm.Name(EnityCode) ;
cm.NotNullable(真);
});
});
};
如何/我在哪里指定AnsiString类型(这样对代码查询是参数为VARCHAR代替为nvarchar'的SQL构造时)的?
我使用SQL Server 2008中。
ca.Property(X => x.Code,地图= GT;
{
map.Type(NHibernateUtil.AnsiString) ;
map.Column(/ *等* /);
});
I'm trying to map an Entity with a string property to a varchar column in NHibernate 3 using the new Loquacious API but I can't figure out how to specify the Type to use. I am able to correctly map the entity with NHibernate 2 and FluentNHibernate.
NHibernate 2 w/Fluent Mapping
public class EntityMapping : ClassMap<Entity>
{
public EntityMapping()
{
Table("EntityTable");
Id(x => x.EntityId).Column("EntityId").GeneratedBy.Identity();
Map(x=>x.Code).Not.Nullable().Column("EntityCode").CustomType("AnsiString");
}
}
NHibernate 3 w/loquacious API
public Action<IClassMapper<Entity>> CreateMapping()
{
return ca =>
{
ca.Table("Entity");
ca.Id(x => x.EntityId, map =>
{
map.Column("EntityId");
map.Generator(Generators.Identity);
});
ca.Property(x => x.Code, map =>
{
map.Column(cm => {
cm.Name("EnityCode");
cm.NotNullable(true);
});
});
};
How/where do I specify "AnsiString" (so queries against code are parameterized as 'varchar' instead of 'nvarchar' when the SQL is constructed)?
I am using Sql Server 2008.
ca.Property(x => x.Code, map =>
{
map.Type(NHibernateUtil.AnsiString);
map.Column(/*etc.*/);
});
这篇关于NHibernate的3指定与能说会道的语法SQL数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!