EF Extensions - Materialize from DbDataReader ()

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
Posts: 2
Joined: Fri 10 Apr 2009 15:05

EF Extensions - Materialize from DbDataReader ()

Post by leonardo.montes » Wed 23 Sep 2009 04:30

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...

Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Wed 30 Sep 2009 08:10

Thank you for sharing your experience.

Post Reply