views:

193

answers:

1

Hi All

I am trying to understand how associated entities are updated when using custom modelbinders.

If you have a Product entity with a relationship to a Category entity and you are displaying a list of category choice for a product in a dropdown on a form.

The the user assigns a new category and that change needs to be persisted with the Product. How is the binding implemented to assign the updated category? The properties f the Product are easy enough, but how do you set the Product.Category = category?

Hope that is clear :-)

A: 

Sounds like your custom model binding is there, you're just trying to setup up your relationship between your Product and Category.

To do this you would do something like this:

product.CategoryReference.EntityKey = new EntityKey("Context.Category", "ID", categoryID);

That will simply update the foreign key relationship in your entity.

RailRhoad
Thanks for the reply. I am using nhibernate however and assume your code is referring to linq to sql?