本文介绍了将字符串设置为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 a varchar 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 the CustomSqlType, strings are mapped to nvarchar (which does respect the Length property).

Any suggestions?

解决方案

Use .CustomType("AnsiString") instead of default "String" and NHibernate will use varchar instead of nvarchar.

这篇关于将字符串设置为SQL类型的“varchar”代替“nvarchar”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 03:49