Essentially, I have a table with zip codes. The zipcode field is defined as "char (5)". I use the code first, so I put these attributes in my ZipCode property:
[Key, Column( Order = 0, TypeName = "nchar"), StringLength(5)] public string ZipCode { get; set; }
Now, if I ask about this in EF:
var zc = db.ZipCodes.FirstOrDefault(zip => zip.ZipCode == "12345");
Generated SQL uses nvarchar (4000) to enter parameters. A? Is it because "12345" is technically a string of unknown length? Should EF be smart enough to just use the proper "nchar (5)" when querying this table?
I ask because the nvarchar (4000) request takes half a second, while the request with the correct scope is much faster (and less read).
Any help / advice would be appreciated.
source share