locked
Entity Framework Inheritance and Persisted Column RRS feed

  • Question

  • Hello, I'm having some problems in entity framework because of an inheritance. So, I have something like this database:

    PROFILE
    Id int identity [PK]
    ProfileTypeId int [FK] [PK]

    PROFILETYPE
    Id int [PK]

    COMPANY
    ProfileId int [FK] [PK]
    ProfileTypeId AS 1 PERSISTED [FK] [PK]

    PERSON
    ProfileId int [FK] [PK]
    ProfileTypeId AS 2 PERSISTED [FK] [PK]

    I want to implement inheritance, an PROFILE can be an COMPANY or PERSON, and it is exclusive, so the FK in COMPANY is ProfileId and ProfileTypeId to PROFILE to make it exclusive.

    But when I try to create an company in the entity framework it violates the FK in the PROFILE to the PROFILETYPE. Probably because in the COMPANY the ProfileTypeId is persisted, it is not filling the value in the PROFILE, does anyone knows an workaround to make it work with the entity framework?

    Thanks!

    Friday, May 27, 2011 3:56 AM

Answers

  • Hello,

    it looks like the same question on Stack overflow where the answer was accepted. The answer contains description why this will not work in EF - EF handles PERSISTED column as computed and computed columns are never send to the database and it also should not allow making computed column part of FK or PK.

    Best regards,
    Ladislav

    • Proposed as answer by Alan_chen Tuesday, May 31, 2011 6:56 AM
    • Marked as answer by Alan_chen Tuesday, June 7, 2011 2:12 AM
    Friday, May 27, 2011 9:26 AM

All replies

  • Hello,

    it looks like the same question on Stack overflow where the answer was accepted. The answer contains description why this will not work in EF - EF handles PERSISTED column as computed and computed columns are never send to the database and it also should not allow making computed column part of FK or PK.

    Best regards,
    Ladislav

    • Proposed as answer by Alan_chen Tuesday, May 31, 2011 6:56 AM
    • Marked as answer by Alan_chen Tuesday, June 7, 2011 2:12 AM
    Friday, May 27, 2011 9:26 AM
  • Hi programlin,

    I am writing to check the status of the issue on your side.  Would you mind letting us know the result of the suggestions?

    If you need further assistance, please feel free to let me know.   I will be more than happy to be of assistance.

     

    Have a nice day.

     


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, May 31, 2011 6:55 AM