'Is there problem with specifying all string columns as VARCHAR(MAX)

I have an Entity Framework application that is connecting to a non-unicode database. If I leave all my mapped string columns as the default type, Entity Framework sends query parameters as unicode values as shown below, and my performance seems to suffer.

exec sp_executesql N'SELECT [s].[Something]
FROM [MyTable] AS [s]
WHERE [s].[id] = @__id_0',N'@__id_0 nvarchar(450)',@__id_0=N'123456'

If I change my mapping to specify a VARCHAR column type, the query performance improves.

modelBuilder.Entity<MyObject>().Property(p => p.Id).HasColumnName("id").HasColumnType("VARCHAR(10)");

I'd rather not have to specify the column lengths of each field individually. Is there a problem with specifying all my column mappings as VARCHAR(MAX) (not the actual columns; those will still have a defined length), assuming that I either never write to that table or I handle truncating the string to the appropriate length within my application?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source