Skip to content

Respect ColumnAttribute #2

@moozzyk

Description

@moozzyk

Ported from https://codefirstfunctions.codeplex.com/workitem/15

REPORTED ON:
REPORTED BY:
Oct 13, 2015 at 3:25 AM
samunro

The ColumnAttribute allows for property names that do not match the columns in the database to be mapped correctly in an Entity Framework Code First model.

This attribute does not appear to be respected by codefirstfunctions.

As an example, this is an error that I saw.

System.Data.Entity.Core.EntityCommandExecutionException: The data reader is incompatible with the specified '<Class Name>'. A member of the type, '<Property Name>', does not have a corresponding column in the data reader with the same name. 
at System.Data.Entity.Core.Query.InternalTrees.ColumnMapFactory.GetMemberOrdinalFromReader(DbDataReader storeDataReader, EdmMember member, EdmType currentType, Dictionary2 renameList) 
at System.Data.Entity.Core.Query.InternalTrees.ColumnMapFactory.GetColumnMapsForType(DbDataReader storeDataReader, EdmType edmType, Dictionary2 renameList) 
at System.Data.Entity.Core.Query.InternalTrees.ColumnMapFactory.CreateColumnMapFromReaderAndType(DbDataReader storeDataReader, EdmType edmType, EntitySet entitySet, Dictionary2 renameList) 
at System.Data.Entity.Core.Query.InternalTrees.ColumnMapFactory.CreateFunctionImportStructuralTypeColumnMap(DbDataReader storeDataReader, FunctionImportMappingNonComposable mapping, Int32 resultSetIndex, EntitySet entitySet, StructuralType baseStructuralType) 
at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.FunctionColumnMapGenerator.System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.IColumnMapGenerator.CreateColumnMap(DbDataReader reader) 
at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.CreateColumnMap(DbDataReader storeDataReader, Int32 resultSetIndex) 
at System.Data.Entity.Core.Objects.ObjectContext.MaterializedDataRecord[TElement](EntityCommand entityCommand, DbDataReader storeReader, Int32 resultSetIndex, ReadOnlyCollection1 entitySets, EdmType[] edmTypes, ShaperFactory1 shaperFactory, MergeOption mergeOption, Boolean streaming) 
at System.Data.Entity.Core.Objects.ObjectContext.CreateFunctionObjectResult[TElement](EntityCommand entityCommand, ReadOnlyCollection1 entitySets, EdmType[] edmTypes, ExecutionOptions executionOptions) 
at System.Data.Entity.Core.Objects.ObjectContext.<>c__DisplayClass471.<ExecuteFunction>b__46() 
at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) 
at System.Data.Entity.Core.Objects.ObjectContext.<>c__DisplayClass471.<ExecuteFunction>b__45() 
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func1 operation) 
at System.Data.Entity.Core.Objects.ObjectContext.ExecuteFunction[TElement](String functionName, ExecutionOptions executionOptions, ObjectParameter[] parameters) 
at System.Data.Entity.Core.Objects.ObjectContext.ExecuteFunction[TElement](String functionName, MergeOption mergeOption, ObjectParameter[] parameters) 
at System.Data.Entity.Core.Objects.ObjectContext.ExecuteFunction[TElement](String functionName, ObjectParameter[] parameters)... 

Adding the ColumnAttribute to the property referenced in the error did not resolve the issue.

moozzyk wrote Oct 14, 2015 at 12:47 PM [x]

Related http://codefirstfunctions.codeplex.com/discussions/645574

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions