views:

188

answers:

3

I have two EF entities. One has a property called HouseNumber. The other has two properties, one called StartHouseNumber and one called EndHouseNumber.

I want to create a many to many association between these elements based on whether or not HouseNumber falls between StartHouseNumber and EndHouseNumber. However, I can only seem to get an equals operator in the GUI.

Is there a way I'm missing to accomplish this association by range?

+1  A: 

So after considerably more reading on this topic, the answer is that you can't do this, but also that it is an undesired behavior to have.

Associations in the entity framework must be read-write. If I create the association I described, what would happen if I added one of the entities to the other entity's association collection? What value would it choose for HouseNumber to make it fall between the Start and End values?

The correct way to do this is either to write a helper function that takes an argument for HouseNumber, and place this on a hand-coded partial class of the second entity. You'd also either write a read-only property to do the look up or a getter method. Alternatively, you could write a stored procedure in your database that can do this and import it into the entity.

David Pfeffer
+1  A: 

You can't do this with an association, as far as I know, but you can do it with a query.

Craig Stuntz
+1  A: 

In theory you can do this see this post on creating an Association backed by a view.

But as the others have said it's probably not a good idea.

Alex

Alex James