如何让NHibernate停止使用nvarchar(4000)插入参数字符串? [英] How does one make NHibernate stop using nvarchar(4000) for insert parameter strings?

查看:158
本文介绍了如何让NHibernate停止使用nvarchar(4000)插入参数字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要优化正在由一个域实体上的保存(插入查询)生成的查询。我已经使用Fluent NHibernate配置了NHibernate。
$ b 这是NHibernate在插入用户对投票的响应期间生成的查询:

  exec sp_executesql N'INSERT INTO dbo.Response(ModifiedDate,IpAddress,CountryCode,$ b $ IsRemoteAddr,PollId)VALUES(@ p0,@ p1,@ p2, @ p3,@ p4);选择SCOPE_IDENTITY()',N'@ p0 
datetime,@ p1 nvarchar(4000),@ p2 nvarchar(4000),@ p3位,@ p4 int',
@ p0 ='2001-07 -08 03:59:05',@ p1 = N'127.0.0.1',@ p2 = N'US',@ p3 = 1,@ p4 = 2

如果查看 IpAddress <$的输入参数c $ c> CountryCode ,你会发现NHibernate正在使用 nvarchar(4000) 。问题是 nvarchar(4000)远远大于我所需要的 IpAddress CountryCode ,由于流量和托管需求高,我需要优化数据库的内存使用情况。



以下是这些列的Fluent NHibernate自动映射覆盖:

  mapping.Map(x => x.IpAddress).CustomSqlType(varchar(15)); 
mapping.Map(x => x.CountryCode).CustomSqlType(varchar(6));

这不是我看到不必要的nvarchar(4000)弹出的唯一地方。



如何控制 NHibernate 使用 nvarchar(4000) 为字符串表示?



如何更改此 insert 语句以使用适当大小的输入参数指定类型 NHibernateUtil.AnsiString 长度而不是使用CustomSqlType。


I need to optimize a query that is being produced by a save (insert query) on a domain entity. I've configured NHibernate using Fluent NHibernate.

Here's the query generated by NHibernate during the insertion of a user's response to a poll:

exec sp_executesql N'INSERT INTO dbo.Response (ModifiedDate, IpAddress, CountryCode, 
IsRemoteAddr, PollId) VALUES (@p0, @p1, @p2, @p3, @p4); select SCOPE_IDENTITY()',N'@p0
datetime,@p1 nvarchar(4000),@p2 nvarchar(4000),@p3 bit,@p4 int',
@p0='2001-07-08 03:59:05',@p1=N'127.0.0.1',@p2=N'US',@p3=1,@p4=2

If one looks at the input parameters for IpAddress and CountryCode, one will notice that NHibernate is using nvarchar(4000). The problem is that nvarchar(4000) is far larger than I need for either IpAddress or CountryCode and due to high traffic and hosting requirements I need to optimize the database for memory usage.

Here's the Fluent NHibernate auto-mapping overrides for those columns:

    mapping.Map(x => x.IpAddress).CustomSqlType("varchar(15)");
    mapping.Map(x => x.CountryCode).CustomSqlType("varchar(6)");

This isn't the only place that I see unnecessary nvarchar(4000)'s popping up.

How do I control NHibernate's usage of nvarchar(4000) for string representation?

How do I change this insert statement to use the proper sized input parameters?

解决方案

Specify the Type as NHibernateUtil.AnsiString with a Length instead of using a CustomSqlType.

这篇关于如何让NHibernate停止使用nvarchar(4000)插入参数字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆