Last post Jun 03, 2011 04:57 AM by riggit
Jun 01, 2011 09:28 AM|riggit|LINK
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]'.
Jun 01, 2011 12:20 PM|qwe123kids|LINK
Seems to me Like Mapping Refernce problem
but the required type is
Reslut you are Getting is Item and Required is Comment
Jun 02, 2011 03:37 PM|riggit|LINK
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.
Jun 02, 2011 10:17 PM|Decker Dong - MSFT|LINK
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();
var result = al.OfType<int>();
foreach (var item in result)
Jun 03, 2011 03:10 AM|riggit|LINK
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.
Jun 03, 2011 03:22 AM|Decker Dong - MSFT|LINK
Your codes please，and please point out what's the matter.
Jun 03, 2011 03:49 AM|riggit|LINK
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.).
Jun 03, 2011 04:28 AM|riggit|LINK
The model looks like this:
When DD is run and "Posts" is clicked, the error message is shown.
Jun 03, 2011 04:44 AM|sjnaughton|LINK
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
Jun 03, 2011 04:50 AM|riggit|LINK
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.
Jun 03, 2011 04:57 AM|riggit|LINK
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.