I recently came across this scenario... I needed to build an entity from some stored proc output... while passing the DbDataReader to the Materializer I realized the entity was being built, but all the properties had just default values (0, null, etc...)
While debugging the EF Extensions Materializer.Materialize(DbDataReader) discovered that the DbDataReader.GetName(index) would return the column name UPPERCASED... therefore, the GetProperty method inside the materializer was retrieving null...
Since it's simpler to modify the EF Extensions code, I changed the TryCreateMemberBinding method to use BindingFlags.IgnoreCase
private static bool TryCreateMemberBinding(string columnName, int? ordinal, out MemberBinding memberBinding) {
PropertyInfo propertyInfo = typeof(T).GetProperty(columnName, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);
if (null != propertyInfo) {
if (propertyInfo.GetIndexParameters().Length == 0 && propertyInfo.CanWrite) {
memberBinding = Expression.Bind(propertyInfo.GetSetMethod(), CreateGetValueCall(propertyInfo.PropertyType, columnName, ordinal));
return true;
}
}
memberBinding = null;
return false;
}
... now I wonder how this works outside of the EF Extensions materializer... either someone's ignoring the casing or there's a way to obtain cased column names from Devart.Data.Oracle.OracleDataReader...
Hope this helps someone...
EF Extensions - Materialize from DbDataReader ()
-
- Posts: 2
- Joined: Fri 10 Apr 2009 15:05