0

I'm trying to create an MVC project using Datbase First Modelling in Entity Framework. The issue I have is when I have selected the tables I wish to use, the models are created but relationships are not generated. I have read somewhere that EF does not work well with composite keys which unfortunately a number of my tables are made up of.

I tried adding the associations myself through the designer but because my table has a composite key and its mapping to a table on the first portion of the composite key to a column on another table I get an error. This is because it insists on having a mapping for the second item of the composite key e.g.

Table 1                 Table 2
D_ID                    A_ID
FC                      SomeField
Description             SomeField
etc...                  D_ID

I need to map Table 1 and 2 based on D_ID but Table 1 is made up of a composite Key of D_ID & FC

Using database first how do I get around this?

Thanks

psycho
  • 1,539
  • 4
  • 20
  • 36
  • "I have read somewhere that EF does not work well with composite keys" Where did you read that? It really makes no difference, at least I haven't had a problem with EF using composite keys. – Mohammad Sepahvand Mar 27 '15 at 08:27
  • Are you getting any errors? Possibly related to [this](https://entityframework.codeplex.com/workitem/1735) bug. – Hintham Mar 27 '15 at 09:48
  • yes essentially saying that I need to map for all keys in Table 1. – psycho Mar 27 '15 at 11:54
  • Have you read this? http://stackoverflow.com/questions/1925632/composite-db-keys-with-entity-framework-4-0 – alainlompo Mar 28 '15 at 06:57
  • Do you have to do it with data base first? Could you do it with code first? – alainlompo Mar 28 '15 at 07:04

0 Answers0