本文介绍了将字符串设置为SQL类型的“varchar”代替“nvarchar”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public class LogEntryMap
而不是默认
{
public LogEntryMap()
{
Map.Id(x => x.Id).GeneratedBy.Identity();
Map(x => x.Context).CustomSqlType(varchar)。Length(512);
$ b然而,使用SchemaExport
在SQL Server 2008中生成数据库时,生成的脚本将忽略长度,因此实际上它将变成长度为1的varchar
p>
create table OV_SAC.dbo。[LogEntry](
Id BIGINT IDENTITY NOT NULL,
Context varchar null,
主键(Id)
)
CustomSqlType(varchar 512)
引发异常。没有定义CustomSqlType
,字符串被映射为nvarchar
(它尊重Length
property)。
有什么建议吗?
解决方案.CustomType(AnsiString)
String
,NHibernate将使用varchar
而不是nvarchar
。I have the following mapping:
public class LogEntryMap { public LogEntryMap() { Map.Id(x => x.Id).GeneratedBy.Identity(); Map(x => x.Context).CustomSqlType("varchar").Length(512); } }
However, using
SchemaExport
to generate the database in SQL Server 2008, the script generated ignores the length so in effect it ends up being avarchar
with length of 1:create table OV_SAC.dbo.[LogEntry] ( Id BIGINT IDENTITY NOT NULL, Context varchar null, primary key (Id) )
.CustomSqlType("varchar 512")
throws an exception. And without defining theCustomSqlType
, strings are mapped tonvarchar
(which does respect theLength
property).Any suggestions?
解决方案Use
.CustomType("AnsiString")
instead of default"String"
and NHibernate will usevarchar
instead ofnvarchar
.这篇关于将字符串设置为SQL类型的“varchar”代替“nvarchar”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!