I need to optimize a query created using a save (insert) request for a domain object. I configured NHibernate using Fluent NHibernate.
Here is the query created by NHibernate during the insertion of the user's response to the survey:
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 you look at the input parameters for IpAddress and CountryCode , you will notice that NHibernate uses nvarchar(4000) . The problem is that nvarchar(4000) much larger than I need for IpAddress or CountryCode , and because of the high traffic requirements and For the hosting I need to optimize the database for memory usage.
Here's the automatic mapping of Fluent NHibernate overrides for these columns:
mapping.Map(x => x.IpAddress).CustomSqlType("varchar(15)"); mapping.Map(x => x.CountryCode).CustomSqlType("varchar(6)");
This is not the only place where I see the unnecessary nvarchar (4000).
How to control the use of NHibernate nvarchar(4000) to represent strings?
How do I modify this insert to use input parameters of the correct size?
sql-server hibernate nhibernate fluent-nhibernate nhibernate-mapping
Mark rogers
source share