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 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 sjnaughton on Jan 12, 2013 12:53 PM
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 ).
In summary TPT is a greatway to enforce IsA scenarios but ONLY if it is in one bucket.
JJHayter
Member
16 Points
17 Posts
Table-per-Type not working as intended with Dynamic Data
Dec 26, 2012 04:59 PM|LINK
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):
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.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Table-per-Type not working as intended with Dynamic Data
Dec 27, 2012 07:03 AM|LINK
Hi,
Are you using EF (Db-first) or Code-first?
sjnaughton
All-Star
27308 Points
5458 Posts
MVP
Re: Table-per-Type not working as intended with Dynamic Data
Dec 27, 2012 09:47 AM|LINK
Hi JJHayter, I have asked one of the ASP.Net team to have a look as I have never used TFT myself :(
Always seeking an elegant solution.
JJHayter
Member
16 Points
17 Posts
Re: Table-per-Type not working as intended with Dynamic Data
Dec 27, 2012 08:16 PM|LINK
Db-First since the application existed before migrating to EF (4.x to 4.3.1) using 4.0 .Net
I figure I am missing something simple
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Table-per-Type not working as intended with Dynamic Data
Dec 28, 2012 12:12 AM|LINK
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.
JJHayter
Member
16 Points
17 Posts
Re: Table-per-Type not working as intended with Dynamic Data
Dec 31, 2012 07:53 PM|LINK
The problem is not solved, yet.
pranav rasto...
Member
286 Points
52 Posts
Re: Table-per-Type not working as intended with Dynamic Data
Jan 11, 2013 10:39 AM|LINK
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
JJHayter
Member
16 Points
17 Posts
Re: Table-per-Type not working as intended with Dynamic Data
Jan 11, 2013 10:24 PM|LINK
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
).
In summary TPT is a greatway to enforce IsA scenarios but ONLY if it is in one bucket.