views:

26

answers:

1

I have 3 tables

Table 1

  • Id
  • Name

Table 2

  • Id
  • Name

Link Table

  • Table1Id
  • Table2Id

The link table sets up a many to many relationship between Table 1 and Table 2. I'm using the entity framework which does not automatically create an entity for the Link Table and I need to be able to manage that table directly. Therefore, I need to create an entity for that table.

Here's my question: Am I able to create an entity for the link table as it stands? I know if I add a separate id column to the link table and make that the PK it will create an entity for me, but then I can not set up the association between table 1 and table 2 because the new id property is not mapped. Is there any way around this?

A: 

It looks like that you have to review your database schema. I can remember a project (EF2) with association tables which were all represented by EntityCollections. So we were able to add one entity to the collection of the other entity.

Can you give us some more details of the database schema. Perhaps the diagram or something like this?

DHN
The problem was that I needed to add records to the association table directly. I ended up adding a field to the association table and creating an entity for it. Now, I have to manage the relationship manually in my code, but I can access the association records directly.
aubreyrhodes
Ok, why do you want to access them directly? I have to admit that I don't understand it.
DHN
I'm using a wrapper that generates a webservice from the entity model, but it doesn't currently support adding records to many to many relationships, so I have to add records to the association table directly.
aubreyrhodes
You should have mentioned this. Your problem is the generated DataService stub. Is it a WCF DataService?
DHN