views:

84

answers:

2

I want to make a many to many connection with a field in it.

example: User -----works (hours)----- Company

Hours is a field in the many-to-many table. The field describes how many hours a user works in the company.

How is this best modeled in the entity framework?

Can you even model this without making a entity out of the connection table?

+1  A: 

This would be a one to many to one relationship I believe, i.e. User to Work is one to many and Work to Company is many to one. By breaking the problem into smaller logical chunks you can see the solution often drops out on it's own. I don't think it would be appropriate, given the structure above, to even attempt to not model the Work table.

While this isn't an answer that relates to the entity frameworks, I hope it'll help you structure the problem better in your mind and hopefully guide you to your solution.

Lazarus
I know about how to usa a separate work table. With the entity framework you'd have to create an entity for the connection anyway I think. I wanted the entity framework to hide the work table logic for me. This is why I accept Craig Stuntz answer.
Bård
+1  A: 

Lazarus's answer is basically correct for the way the Entity Framework is today (upvoted), but I realize you're asking for something different. What you want is a property on the many to many association, rather than a separate entity type in the model. The Entity Framework does not presently offer that feature. It may be available in a future release.

Craig Stuntz
Would be a cool feature to have I think.
Bård