通过Fluent NHibenate更改sp_executesql中字符串的参数类型

时间:2016-12-16 12:32:41

标签: c# sql nhibernate fluent-nhibernate fluent-nhibernate-mapping

我有一个NHibernate设置,(简化)看起来像这样:

public class MyClass
{
   public virtual long ID {get;set;}
   public virtual string Code {get;set;}
}

public class MyClassMap : ClassMap<MyClass>
{
   h => h.ID, "rowID");
   Map(h => h.PortfolioCode, "portfolio_code").Length(10);
}

当我创建以下查询时:

    IQueryOver<MyClass> query = repository.MakeQueryOver<MyClass>()
        .Where(m=>m.Code==code));

它使用标准sp_executesql生成sql,这很好,但它使用nvarchar(4000)作为参数的类型。这给我们带来了一些严重的性能问题。当我们复制SQL并在SSMS中运行它需要几分钟时间。当我们将其更改为nVARCHAR(10)时,需要不到一秒钟。

0 个答案:

没有答案
相关问题