C#: DbType.String versus DbType.AnsiString

前端 未结 4 1462
时光说笑
时光说笑 2021-02-04 00:32

I have taken over some C# code.

The code is hitting a database with some SQL which uses parameters.

All of the string parameters are typed as

4条回答
  •  爱一瞬间的悲伤
    2021-02-04 01:17

    You would use ansistring instead of string to avoid implicit conversions in your SQL Server database.

    i.e. when you pass a string variable into MSSQL it appears as nvarchar(max). Given the fact a well designed database in MSSQL may use varchars as opposed to nvarchars by default (unless there is a business requirement for non latin character sets).

    A string variable in this case will cause an implicit conversion in the database. This can then render the engine unable to use certain indexes and perform full table scans (one of the roots of all evil for db performance)

提交回复
热议问题