MS EntityFramework: how to split entity with inheritance? Using of discriminator
I have table name Transaction in the DB. I want to have 2 subclasses TransactionA and TransactionB. I've made it as described here: http://www.robbagby.com/entity-framework/entity-framework-modeling-table-per-hierarchy-inheritance/comment-page-1/#comment-607
The problem is I need to use the field that is discriminator here (see the exa开发者_运维技巧mple, it's PersonCategory there). But it has to be deleted after that I cannot use it.
How to solve this problem? Thanks
If it is a discriminator its only usage is to map record to either TransactionA
or TransactionB
. It cannot be set in the application. It is set if you insert TransactionA
instance or TransactionB
instance and record. It also cannot be updated because object of one type cannot change to object of other type - if you need such logic you cannot model it as inheritance.
Yes it is used as a EF helper to identify type of the specific type of the object. One disadvantage is that approach is every field should be a nullable field and tables are not normalized. However, no joins are involved hence, it is fast approach. Table per type is relatively good approach you have two classes TransactionA and TransactionB with generic class called Transaction.Although, you have to do join as a result of that, performance is not that great compair to earlier approach.
精彩评论