table mapping in entity framework
I have a Model1.edmx, which has several tables. Now, I do not want all the columns of the table TableA, so I created another entity and mapped it with TableA using table mapping.
I am facing lot of issues while doing the same. The error that I get is,
" Thier primary key may collide".
If I create the FK association, it says "Non-Primary-Key column(s) [XXX] are being mapped in both fragments to different conceptual side properties".
I am not sure, if the approach that I am taking is correct, as entity set alraedy exist开发者_运维技巧s for TableA.
If this is the approach what would be the solution.
If not, which way should I go.
UPDATE : I did delete the properties that were not required, also, I added the properties from other tables that were FK in the TableA.
Now I am getting error " Problem in mapping fragments starting at line 566:Must specify mapping for all key properties (TableAs.ID) of the EntitySet TableAs.
"
UPDATE I added the other tables properties as they were FK, and I wanted few columns from the other table in the UI. Is this a good (or possible) approach? or should I create classes for it, and then map each property of the class manually? Thanks in advance.
What you mean by this:
Now, I do not want all the columns of the table TableA, so I created another entity and mapped it with TableA using table mapping.
Is not entirely clear. Do you mean that you only want to deal with a subset of the columns in TableA
and ignore the others everywhere in the application? Assuming they're nullable (or have a StoreGeneratedProperty
of Computed
), you can just click on them in the entity for TableA
and delete them.
You can't create another entity that's mapped to TableA
unless you're dealing with table-per-hierarchy inheritance, which it doesn't sound like you're interested in.
精彩评论