entity framework - Why does code first/EF use 'nvarchar(4000)' for strings in the raw SQL command? -
essentially have table zip codes in it. zipcode field defined 'char(5)'. i'm using code first, i've put these attributes on zipcode property:
[key, column( order = 0, typename = "nchar"), stringlength(5)] public string zipcode { get; set; }
now if query against in ef:
var zc = db.zipcodes.firstordefault(zip => zip.zipcode == "12345");
the generated sql uses nvarchar(4000) inject parameters. huh? because "12345" technically string of unknown length? shouldn't ef smart enough use proper "nchar(5)" when querying table?
i ask because nvarchar(4000) query takes half second whereas properly-scoped query faster (and less reads).
any assistance/advice appreciated.
this take advantage of auto parameterization. following article explains general concept why nvarchar(4000) used.
Comments
Post a Comment