locked
Problem with association in EF 4.0 RRS feed

  • Question

  • I always run into this error when I try to create an associtaion in EF 4.0 (VS 2010)

     

    I have very simple tables

    FMMAST (Table)

    FormulaId (PK)

    Description

    FormulaClassID

    FMITEM (Table)

    FormulaId (PK)

    SequenceNum (PK)

    ItemKey

    Note that there is no foreign key relationship.

    In model if I try to create a simple one to many relationship (association) between FMMAST and FMITEM (I unchecked Add Foreign key properties option). I ran into this error

    Error 1 Error 3021: Problem in mapping fragments starting at line 372:Each of the following columns in table FMItem is mapped to multiple conceptual side properties:
    FMItem.FormulaID is mapped to <FormulaFormulaItem.FormulaItem.FormulaID, FormulaFormulaItem.Formula.FormulaID>

     D:\Net Practice 2010\ExtensionMethods\ExtensionMethods\Model1.edmx 373 11 ExtensionMethods

    I tried deleting the association and adding once again with option "Add Foreign key properties " checked, 2 errors were returned.

    Can any one post a small sample how association be created between two tables where detail table does not have a foreign key.

    thanks,

    Abhishek

    Saturday, May 22, 2010 6:32 AM

Answers

  • Hello,

    Please let me assume you have two tables as follows:
    =================================
    FMMAST(
     FormulaId int PK,
     Description null,
     FormulaClassID int
          )
    =================================
    FMITEM(
     FormulaID int PK,
     SequenceNum PK,
     ItemKey int
          )
    =================================

    You could add an association of the two entities follow the steps below:
     1. right click the designer and select Add -> Association..
     2. check Add foreign key properties to xxx entity check box and click OK
        (after this step, a new Scalar Property will be added to xxx entity, for example, FormulaID1)
     3. delete a Scalar property of FMITEM entity, for example, ItemKey property.
     4. Open Mapping detail window and map the added FormulaId1 property to ItemKey column.
     5. right click the designer and select Validate.

    Please follow up the steps and have a try and let me know if there are any question.

    Best regards


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have any feedback, please tell us.
    Welcome to the All-In-One Code Framework!
    Tuesday, May 25, 2010 8:56 AM