Is there an option to make Entity Framework revert empty strings to null?
问题 I am using an ADO.NET Entity-Framework ObjectContext to access my data store. I want the if values are set with empty strings, they should automatically become null. 回答1: If your using Entity Framework 4, you can use T4 templates to accomplish this. Just place this in the getter of each string property in your .tt template file, and it will replace empty strings with null and automatically trim strings. No need to use reflection. <#+ if (primitiveProperty.TypeUsage.ToString().Split('.').Last(