locked
Dynamic Data with Entity Framework 4 Table Per Type Ineritence, TPT RRS feed

  • Question

  • User-1714319972 posted

    Hi there,

    I've searched quite a lot but can't find a solution to using Dynamic Data with EF TPT inheritence.

    The actual model seems to work fine for use with "normal" code. For example, a LINQ query with Items.OfType<Comment> works fine.

    I get the following error message, where "Item" is the base type and "Comment" is a sub-type.

    Thanks for help in advance.

    The ResultType of the specified expression is not compatible with the required type. The expression ResultType is 'Transient.reference[Model.Item]' but the required type is 'Transient.reference[Model.Comment]'.

    Wednesday, June 1, 2011 9:28 AM

Answers

All replies

  • User-1659704165 posted

    Hi,

    Seems to me Like Mapping Refernce problem

    'Transient.reference[Model.Item]'

    but the required type is

    'Transient.reference[Model.Comment]'.

    Reslut you are Getting is Item and Required is Comment

    Wednesday, June 1, 2011 12:20 PM
  • User-1714319972 posted

    Hi,

    Thanks for the reply. I can see that is what the error message says, but I need help in getting to the bottom of it.

    The error suggests that there is an issue with the model mapping, but the model works fine as in the example snippet I quoted.

    The issue seems to be in Dynamic Data not working very well with TPT inheritence. Is it meant to?

    Dynamic Data appears to confuse the base type with the sub-type.

    Regards

     

    Thursday, June 2, 2011 3:37 PM
  • User3866881 posted

    Hello:)

    The extended method——OfType<T> will help you to find in a collection which are belonging to the certain types.

    This is a very simple LINQ sample——


            static void Main(string[] args)
            {
                ArrayList al = new ArrayList();

                al.Add(1);
                al.Add("1");
                al.Add(1.0);

                var result = al.OfType<int>();

                foreach (var item in result)
                {
                    Console.WriteLine(item);
                }
            }

    Thursday, June 2, 2011 10:17 PM
  • User-1714319972 posted

    Hi there,

    Thanks for your reply!

    As mentioned in my original post, I am already able to use OfType<T>() successfully with the data model.

    The problem I am having is with the automatically generated Dyanamic Data pages.

    When the DD pages involve base entities and derived types they don't work and give the error above.

    Thanks again

    Regards

    Friday, June 3, 2011 3:10 AM
  • User3866881 posted

    Hello:)

    Your codes please,and please point out what's the matter.

    Thx

    Friday, June 3, 2011 3:22 AM
  • User-1714319972 posted

    Hi there,

    Thanks for the reply.

    Ok I will post the model structure.

    There basically isn't any code to show, as it's basically a virgin Dynamic Data website at the moment (I.e. I haven't modified the code/added DD partial classes/attributes etc.).

    Regards

    Friday, June 3, 2011 3:49 AM
  • User-1714319972 posted

    The model looks like this:

    Dynamic Data TTP Problem

    When DD is run and "Posts" is clicked, the error message is shown.

     

    Friday, June 3, 2011 4:28 AM
  • User-330204900 posted

    I've just had a reply from the team and Pranav has a sample which I can e-mail you, it's based on this

    article http://msdn.microsoft.com/en-us/library/cc716702.aspx you can get my e-mail address from my blog C# Bits

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 3, 2011 4:44 AM
  • User-1714319972 posted

    Hi there,

    I've resolved this. I forgot to delete the "associations" (dotted lines in picture above) after creating the inheritence.

    Tip: Don't forget to set the base type to abstract!

    Regards and thanks for the help.

    Regards

    Friday, June 3, 2011 4:50 AM
  • User-1714319972 posted

    Hi Stephen!

    Thanks for the reply.

    I actually just read that run-through just before reading your help.

    I'd setup DD with TPT a few times before but for some reason I missed a couple of things this time, like deleting the associations.

    Thanks again for looking into this for me.

    Even though my issue was already sorted, I'll mark your reply as the answer, as it would have been the solution had I not found it myself.

    Regards

    Kevin

    Friday, June 3, 2011 4:57 AM