0
votes

I am using Database First EF to generate model from the existing database. When I first generated the models, it ignores only one of the table, the entity was not added to EDMX, no model file is created for the table and no context is created for the entity.

When I tried to explicitly add the table to EDMX (when generating the model, selected the specific table first and then updated the model with all the other tables from the database), it complained with the following error.

Two entities with possibly different keys are mapped to the same row. Ensure these two mapping fragments map both ends of the AssociationSet to the corresponding columns.

This specific table has two columns which are primary keys of some other tables and both the columns are specified as Primary keys for the table.

Am I doing something wrong or should I handle this table differently since it has two columns defined as Primary Keys? Any suggestions greatly appreciated!

1
uhm ... Isn't the whole idea of Code First to generate the database from code? not the other way around? (either that... or i totally don't understand your question)Yoeri
You are right, I have updated the question. Thanks anyway!inspiringmyself

1 Answers

1
votes

You are not doing anything wrong. Your table is junction table for many-to-many relation. You don't need that table in the model because EF (in contrast to database) can handle many-to-many relation directly without any intermediate. The table is actually mapped on behind of the many-to-many relation - you will see that in mapping details window.

Btw. you are not using code first. Code first = no EDMX.