Friday, March 1, 2013

Entity framework and varchar

Just learned about EF and varchar types. EF strings are unicode and when querying database, it will cause performance problems (I was surprised by this, one would assume it should cast to varchar first...). There are 2 solutions, one is to use EntityFunctions.AsNonUnicode, i.e. from t in table where t.id == EntityFunctions.AsNonUnicode(id) The other is use attribute, [Column(TypeName = "varchar")] on the field.