Showing posts with label Entity Framework. Show all posts
Showing posts with label Entity Framework. Show all posts

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.

Wednesday, February 13, 2013

EF decimal precision

Encountered a strange problem at work. Entity framework code first, entity's decimal field always save to 2 decimal points even though the field has 4. Turned out in EF4 you need to specify percision: modelBuilder.Entity().Property(e=> e.property).HasPrecision(x, d);