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.

http://msdn.microsoft.com/en-us/magazine/ee236412.aspx


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -