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

后端 未结 4 2038
梦谈多话
梦谈多话 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:16

    This issue can cause a huge performance problem in queries if it forces SQL Server to perform a table scan instead of using an index. We use varchar throughout our database so I created a convention to set the type globally:

    /// 
    /// Convert all string properties to AnsiString (varchar). This does not work with SQL CE.
    /// 
    public class AnsiStringConvention : IPropertyConventionAcceptance, IPropertyConvention
    {
        public void Accept(IAcceptanceCriteria criteria)
        {
            criteria.Expect(x => x.Property.PropertyType.Equals(typeof(string)));
        }
    
        public void Apply(IPropertyInstance instance)
        {
            instance.CustomType("AnsiString");
        }
    
    }
    

提交回复
热议问题