locked
Table-per-Type not working as intended with Dynamic Data RRS feed

  • Question

  • User-396224324 posted

    I am  having a bit of difficulty with TPT and the Entity Frame work (EF 4.3.1). It occured to me that I may have missed a  fundamental setting so I would like to know why it is not working.

    I have a base table (Accounts) which can be of several child types(Debts, Checkings, Savings, ect). 

    I also have a base table (Persons) which can be of several child types(Employers, PortalUsers, Clients, ect). 

    In short I treat these base tables like a graph where the Account's Id can belong in multiple tables (which is still unique via NewSequentialId). The same applies to Persons.

    Error Codes:

    All objects in the EntitySet 'Z10Entities.Accounts' must have unique primary keys. However, an instance of type 'DAL.Model.CreditCardAccount' and an instance of type 'DAL.Model.Debt' both have the same primary key value, 'EntitySet=Accounts;Id=3'.

    All objects in the EntitySet 'Z10Entities.Person' must have unique primary keys. However, an instance of type 'DAL.Model.Employer' and an instance of type 'DAL.Model.PortalUser' both have the same primary key value, 'EntitySet=Person;Id=1b64b850-34f9-e111-bdc8-000c29005764'.

    Here is a picture of the Tables (Persons omitted for clarity):

    TPT Accounts

    No progress has been made on the thread on the original question I asked on StackOverflow http://stackoverflow.com/questions/13730763/need-insight-on-tpt-ef4-when-inserting-with-dynamic-data so I will include the link just in case.

    Wednesday, December 26, 2012 12:59 PM

Answers

  • User1155138559 posted

    TPT in dynamic data should work…Judging from the image of the model posted on the forum, it does not look to be TPT and is incorrect

    http://msdn.microsoft.com/en-US/data/jj618293 is a good tutorial that walks you through creating a TPT model. Please do try your model outside of a DYnamicdata application to make sure if it works in general

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, January 11, 2013 6:39 AM

All replies

  • User3866881 posted

    Entity Frame work (EF 4.3.1).

    Hi,

    Are you using EF (Db-first) or Code-first?

    Thursday, December 27, 2012 3:03 AM
  • User-330204900 posted

    Hi JJHayter, I have asked one of the ASP.Net team to have a look as I have never used TFT myself :(

    Thursday, December 27, 2012 5:47 AM
  • User-396224324 posted

    JJHayter

    Entity Frame work (EF 4.3.1).

    Hi,

    Are you using EF (Db-first) or Code-first?

    Db-First since the application existed before migrating to EF (4.x to 4.3.1) using 4.0 .Net

    Hi JJHayter, I have asked one of the ASP.Net team to have a look as I have never used TFT myself :(

    I figure I am missing something simple Embarassed

    Thursday, December 27, 2012 4:16 PM
  • User3866881 posted

    Hi

    I see the state of this issue is marked as an answer……Is your problem solved?

    If yes, I'll close the issue; otherwises please feel free to feedback.

    Thursday, December 27, 2012 8:12 PM
  • User-396224324 posted

    The problem is not solved, yet. Smile

    Monday, December 31, 2012 3:53 PM
  • User1155138559 posted

    TPT in dynamic data should work…Judging from the image of the model posted on the forum, it does not look to be TPT and is incorrect

    http://msdn.microsoft.com/en-US/data/jj618293 is a good tutorial that walks you through creating a TPT model. Please do try your model outside of a DYnamicdata application to make sure if it works in general

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, January 11, 2013 6:39 AM
  • User-396224324 posted

    I have resolved my problem. I had a fundamental misunderstanding of how I wanted to handle what accounts can be marked as debts. Business logic states a credit card can be closed but must be paid off and checking accounts (as an example) can be charged off and now perceived as a valid debt to collect on.

    TPT while good at splitting up accounts in varying buckets does not handle this type of design due to the PK to PK pattern. FK to PK will work if pointed at the base table. With that subtle change and a FK column added I now have acheived the desired functionality (with a performance boost as a pat on the back Cool ).

    In summary TPT is a greatway to enforce IsA scenarios but ONLY if it is in one bucket.

    Refactored Design

    Friday, January 11, 2013 6:24 PM