How does one make NHibernate stop using nvarchar(4000) for insert parameter strings?

后端 未结 4 2030
梦谈多话
梦谈多话 2021-02-14 09:38

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 ge

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-14 10:26

    Here is a work around, if you want to replace all nvarchar with varchar

    public class Sql2008NoNVarCharDriver : Sql2008ClientDriver
    {
        public override void AdjustCommand(IDbCommand command)
        {
            foreach (System.Data.SqlClient.SqlParameter x in command.Parameters)
            {
                if (x.SqlDbType == SqlDbType.NVarChar)
                {
                    x.SqlDbType = SqlDbType.VarChar;
                }
            }
            base.AdjustCommand(command);
        }
    }
    

    Then plug it into your config

    var cfg = Fluently.Configure()
                .Database(MsSqlConfiguration.MsSql2008.ConnectionString(connectionString)
                .Driver())
                ...
    

提交回复
热议问题