locked
Entities mapping RRS feed

  • Question

  • Hello,

     

    This post is somehow related to a previous one.

     

    We have the following structures in the database:

    - 3 tables: A (ID, Name), B (ID, Name), C (ID, IDF, Description, Corresp). The primary keys are A.ID, B.ID and C.ID.

     

    Table A and table B are linked to table C through a foreign key on A.ID = C.IDF and B.ID = C.IDF. Yet the corresponding linked rows are determined by the value in field Corresp.

    If the value in Corresp = 1, then the current row is linked to table A.

    If the value in corresp = 2, then the current row is linked to table B.

    I know that this type of relationship would make Codd go mad, but I must conform to it and I cannot change it.

     

    I must implement this structure by the entity framework. I have tried it 2 ways, as it follows:

     

    1. Via inheritance - failure

     

    I have created in the entity data model the 2 entities (A and B). Then I have created 2 entities (C1 and C2) having the base class C. The entity C has been setted as an abstract one.

    The entity C1 has only one column (Corresp) which is mapped, and a condition (Corresp = 1).

    The entity C2 has only one column (Corresp) which is mapped, and a condition (Corresp = 2).

     

    I have checked the inheritance writing a small piece of code, it seems to be correctly implemented, the code running without failures. Yet after building it, I keep on being shown the message " Entity types C1, C2, C are mapped to table C without discriminating conditions on all mappings to the table." . According to this post (http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3324129&SiteID=1)l it seems to be a bug so i have ignored the message.

     

    Then i have added to the model 2 more entities (A and B) with the corresponding mappings. I have also associated them to the entity C.

     

    Compiling the project, there are no new errors, but when executing the test code, The following error  occurred:

    "Error 3007: Problem in Mapping Fragment(s) starting at line(s) (154, 162): Non-primary-key column(s) [IDF] being mapped in both fragments to different conceptual side properties - data inconsistency is possible because the corresponding �conceptual side properties can be independently modified."

     

    I have removed the associations and I have attached A to C1 and B to C2 - I have received a similar error message when running the test code.

     

    2. Via views - failure.

    I have created in the database 2 views: vC1 and vC2. Both of them are table C views, obtained after applying different filter conditions (C.Corresp = 1 and  C.Corresp = 2, respectively) in the select phrase that generated them.

     

    On the edmx file, I have added the entities A, B, vC1 and vC2, all of them mapped to their corresponding tables.

    After running the same test as above, I have received a similar message.

     

    My questions are:

    - Basically it seems that the problems resume to one problem, this is whether you can or not map in the edmx a structure consisting in more than 1 tables referenced to the same field in a table. According to this post (http://forums.microsoft.com/msdn/showpost.aspx?postid=2654952&siteid=1), this is a limitation of the entity framework. Is is correct?

    What alternatives do I have in this situation?

     

    Thank you,

    K.

     

    P.S. If necesary. I can provide the source files (edmx etc.)

    Thursday, July 24, 2008 10:55 AM

Answers

  • I think the second approach using views should work fine. Can you forward me the edmx file to srimand at microsoft dot com.

     

    Thanks

    Srikanth

     

    Wednesday, July 30, 2008 4:15 AM