locked
TPH Inheritance - type inheritance RRS feed

  • Question

  • Hi,

    I've come across a issue while using EF Beta 3. I have a model with 2 inherited types.

     

    TABLE_A (ID, Name, Type, Date)

     

    TYPE_A (ID, Name, Date)

     

    TYPE_1 (Type=10)

     

    TYPE_2 (Type=11)

     

    TYPE_1 and TYPE_2 inherit from TYPE_A.

     

    The design tool validates the model fine. however when I do a simple Entity Linq query i get the following error. Any ideas please?

     

    Thanks

     

     

    Error Message:

    Test method TestProject1.UnitTest1.TestGetNewsItemDirect threw exception:  System.Data.QueryException: A 'Mapping' exception occurred while processing the query, see inner exception --->  System.Data.MappingException: The number of members on the 'C' side type 'MyModel.NewsItem' does not match with the number of members on the 'O' side type 'MyModel.NewsItem'. Please make sure the number of members are the same..

     

    Error Stack Trace:

    System.Data.Mapping.DefaultObjectMappingItemCollection.LoadEntityTypeOrComplexTypeMapping(ObjectTypeMapping objectMapping, EdmType edmType, EdmType objectType, DefaultObjectMappingItemCollection ocItemCollection, Dictionary`2 typeMappings)
    System.Data.Mapping.DefaultObjectMappingItemCollection.LoadObjectMapping(EdmType edmType, EdmType objectType, DefaultObjectMappingItemCollection ocItemCollection, Dictionary`2 typeMappings)
    System.Data.Mapping.DefaultObjectMappingItemCollection.LoadObjectMapping(EdmType cdmType, EdmType objectType, DefaultObjectMappingItemCollection ocItemCollection)
    System.Data.Mapping.DefaultObjectMappingItemCollection.TryGetMap(String identity, DataSpace typeSpace, Boolean ignoreCase, Map& map)
    System.Data.Metadata.Edm.MetadataWorkspace.TryGetMap(String typeIdentity, DataSpace typeSpace, Boolean ignoreCase, DataSpace mappingSpace, Map& map)
    System.Data.Metadata.Edm.ClrPerspective.TryGetTypeByName(String fullName, Boolean ignoreCase, TypeUsage& typeUsage)
    System.Data.Common.EntitySql.TypeResolver.ResolveNameAsType(String[] names, Int32 countNames, Int32& matchCount)
    System.Data.Common.EntitySql.SemanticResolver.ResolveNameAsType(String[] names, Expr astTypeExpression)
    System.Data.Common.EntitySql.SemanticAnalyzer.ConvertTypeIdentifier(Expr typeIdentifierExpr, SemanticResolver sr)
    b__29(BuiltInExpr bltInExpr, SemanticResolver sr)
    System.Data.Common.EntitySql.SemanticAnalyzer.ConvertBuiltIn(Expr astExpr, SemanticResolver sr)
    System.Data.Common.EntitySql.SemanticAnalyzer.Convert(Expr astExpr, SemanticResolver sr)
    System.Data.Common.EntitySql.SemanticAnalyzer.ConvertGeneralExpression(Expr astExpr, SemanticResolver sr)
    System.Data.Common.EntitySql.SemanticAnalyzer.ConvertCommand(CommandExpr astCommandExpr, SemanticResolver sr)
    System.Data.Common.EntitySql.SemanticAnalyzer.Analyze(Expr astExpr)
    System.Data.Common.EntitySql.CqlQuery.AnalyzeSemantics(Expr astExpr, Perspective perspective, ParserOptions parserOptions, Dictionary`2 parameters, Dictionary`2 variables)
    System.Data.Common.EntitySql.CqlQuery.AnalyzeSemantics(Expr astExpr, Perspective perspective, ParserOptions parserOptions, Dictionary`2 parameters, Dictionary`2 variables)
    System.Data.Common.EntitySql.CqlQuery.Compile(String query, Perspective perspective, ParserOptions parserOptions, Dictionary`2 parameters, Dictionary`2 variables, Boolean validateTree)
    CreateCommandTree()
    System.Data.Objects.ELinq.ExpressionConverter.TranslateInlineQueryOfT(IObjectQueryOfT inlineQuery)
    System.Data.Objects.ELinq.ExpressionConverter.ConstantTranslator.TypedTranslate(ExpressionConverter parent, ConstantExpression linq)
    Translate(ExpressionConverter parent, Expression linq)
    System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
    System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.OneLambdaTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, DbExpression& source, DbExpressionBinding& sourceBinding, DbExpression& lambda)
    System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.OneLambdaTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
    System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, SequenceMethod sequenceMethod)
    System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)
    Translate(ExpressionConverter parent, Expression linq)
    System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
    System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.OneLambdaTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, DbExpression& source, DbExpressionBinding& sourceBinding, DbExpression& lambda)
    System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SelectTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
    System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, SequenceMethod sequenceMethod)
    System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)
    Translate(ExpressionConverter parent, Expression linq)
    System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
    System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.UnarySequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
    System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, SequenceMethod sequenceMethod)
    System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)
    Translate(ExpressionConverter parent, Expression linq)
    System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
    System.Data.Objects.ELinq.ExpressionConverter.Convert(Span& span, Nullable`1& mergeOption)
    BuildCommandTree()
    GetResults()
    GetEnumerator()
    System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
    b__0[TResult](IEnumerable`1 sequence)
    System.Data.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable`1 query, Expression queryRoot)
    System.Data.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.ExecuteSleep(Expression expression)
    System.Linq.Queryable.First[TSource](IQueryable`1 source)
    DataAccessFunctions.vb: line 94
    UnitTest1.vb: line 76

     

     

     

     

     

     

     

    Wednesday, January 23, 2008 11:22 AM

Answers

  • I guess you’ve added one or more properties to your C# (or VB.NET) class but you haven’t described them in your model. Is that correct? Entity Framework requires that all object- and entity properties are mapped to the store.

     

    Zlatko Michailov

    Program Manager, Entity Services

    Microsoft Corp.

    http://blogs.msdn.com/esql

     

    Thursday, January 24, 2008 6:37 AM

All replies

  • If I were you, I would try to delete and redo the edm. I already had the same schema type without problem.

    Wednesday, January 23, 2008 1:01 PM
  • Can you please share your mapping files (csdl, msl and ssdl) (Sanitized if necessary).

     

    That way we can see what you are doing.

     

    The call stack doesn't give us enough to work on in absence of a model.

     

    Cheers

    Alex

    Wednesday, January 23, 2008 4:52 PM
  •  

    Hi,

    I did recreate the model using the new version of EF and Tool.

     

    I shall post the bits tomorrow.

     

    Thanks

    Wednesday, January 23, 2008 11:02 PM
  • I guess you’ve added one or more properties to your C# (or VB.NET) class but you haven’t described them in your model. Is that correct? Entity Framework requires that all object- and entity properties are mapped to the store.

     

    Zlatko Michailov

    Program Manager, Entity Services

    Microsoft Corp.

    http://blogs.msdn.com/esql

     

    Thursday, January 24, 2008 6:37 AM
  • We have seen a few instances where the generated code somehow gets out of sync with the model. The easiest way to fix this is usually to right-click your edmx file and select "Run Custom Tool", which will cause the code to be regenerated.

    Thursday, January 24, 2008 6:07 PM
  • I think the class being out of sync was the issue. but i think i'd made an experimental change in it before I went on holiday and after long exposure to sunshine i'd completely forgotten about that.

     

    by the time i saw the last 2 post i'd recreated the model and in the process noticed my unittest complain about a property which isn't part of the data model (so i must have added this manually).

     

    thanks for your help. .. till the next issue Smile

    Thursday, January 24, 2008 7:33 PM