Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect ColumnAttribute #2

Open
moozzyk opened this issue Nov 19, 2016 · 1 comment
Open

Respect ColumnAttribute #2

moozzyk opened this issue Nov 19, 2016 · 1 comment

Comments

@moozzyk
Copy link
Owner

moozzyk commented Nov 19, 2016

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

@CodeTroopers
Copy link

I have this problem when i call a table valued function that return these entities :

public class Location
{
	[Column("IDX_PARENT")]
	public int ParentId { get; set; }
	public int Level { get; set; }
	public string Root { get; set; }
	[Column("IDX_LOCALISATION")]
	public int Id { get; set; }
}
[DbFunction("EntityDbContext", "GetChildrenLocations")]
public IQueryable<Location> GetChildrenLocations(int rootId)
{
	return ((IObjectContextAdapter)this).ObjectContext.CreateQuery<ChildLocation>(string.Format("[{0}].[GetChildrenLocations](@Root)", this.GetType().Name), new ObjectParameter("Root", rootId));
}

There is a mapping exception :

Invalid column name 'Id', Invalid column name 'ParentId'

Is ColumnName attribute will be supported in the next release?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants