0

I have to create an application which allows to create connections between multiple entities (tables). For example:
- Link between person and room.
- Link between person and person.
- Link between activity and person.
etc. etc. etc.

I plan to create one connection table with no real DB foreign keys. The table has following fields: Connection1, Connection1Type, Connection2, Connection2Type
The Type field defines the entity type. I think it is the most flexible solution.

How can I solve it with the Code First approach??? I think, then I define my entities the EF model builder will try to create foreign keys between the tables and the connection table. In my entities, I would like to have a property called "Connections". This property contains all connections of this entity.

Is it possible?

Thanks in advance.

user1401611
  • 163
  • 1
  • 10
  • The question must be asked: why? Why do all kinds of stuff that a database and EF are very good at? No associations, no navigation properties, no `Include`, _no integrity checks_ (!) except the ones you program yourself, hopefully without forgetting one. – Gert Arnold May 17 '12 at 22:06
  • @GertAnrnold. Well, show me a better way. :) I know that I lose a lot of cool EF functions this way. The both fields (connection1 and connection2) in the "Connection" table must be linked (FK) to every other table. Is this possible??? I don't have a plan how to realize this in EF :/ At least. Mssql doesn't support one single column as a foreign key to multiple tables. – user1401611 May 18 '12 at 05:37
  • Why not regular FK's person-room etc.? Or several junction tables to model many-many relationships? (Probably person-person). Maybe you're referring to polymorphic associations? There are [ways to implement these](http://stackoverflow.com/questions/8895806/how-to-implement-polymorphic-associations-in-an-existing-database) as well with strong FK's. – Gert Arnold May 18 '12 at 06:13
  • Polymorphic associations sounds good. I think, this is a way to go. I'll try it. Thanks! – user1401611 May 18 '12 at 06:21
  • Arent these just a bunch of many-to-many relationships? EF handles those pretty well. – Judo May 18 '12 at 14:23
  • Is a graph database like neo4j a better solution for this???? Let's say, I want to get all the relation between these entities and show them hierarchically. In a RDMS I would create a stored procedure and "prepare" the data. Are there any advantages of a graph database in the development?? Is it a easier and a cleaner way with a graph db? – user1401611 May 25 '12 at 20:46
  • Asking a question in a comment does not work: it will only by luck get any attention and no one likes to answer it. You better ask your second question at [dba.stackexchange](http://dba.stackexchange.com/). – Gert Arnold May 26 '12 at 21:14

0 Answers0