none
Association End Key property is not mapped RRS feed

  • Question

  • Hello,

    I am new to Entity framework. I want to use this in my new project. I started with modelling my relational tables in the EF designer.

    There are few tables in the database which hold more than one key.

    e.g.
    Sector <- Subsector -> Business subsectors
    1.    Sector.SectorID - PK
    2.a. SubSector.SubSectorID - PK
    2.b. SubSector.SectorID - FK
    3.    BusinessSubSectors.SubsectorID - FK

    I have mapped this SubSector entity to both Sectors and BusinessSubsectors.
    But when I compile the solution, it gives me an error for the association between SubSectors -> BusinessSubsectors on SectorID key.

    "Association End Key property SectorID is not mapped."

    Is it necessary to define mapping for all keys in the table/entity even if they are not required in the association, doesnt make any sense to me.

    Can anyone help me with this?

    Thanks,
    Mihir.


    Mihir

    Wednesday, July 11, 2012 9:46 AM

Answers

  • Hi Mihir Mone,

    Welcome to MSDN Forum.

    If the column couldn't be null, but has default value or the column could be null, it could not be mapped. But in your case, 'SectorID' is a PK, so you have to map it.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Monday, July 16, 2012 2:58 AM
    Moderator

All replies

  • Yes, in ef, you have to map all keys, ef will validate the model when you compile the project.

    Go go Doraemon!

    Friday, July 13, 2012 7:20 AM
  • Hi Mihir Mone,

    Welcome to MSDN Forum.

    If the column couldn't be null, but has default value or the column could be null, it could not be mapped. But in your case, 'SectorID' is a PK, so you have to map it.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Monday, July 16, 2012 2:58 AM
    Moderator