views:

15

answers:

0

Hi all
I have a collection of new instances of a linq2SQL object.
They were created by the default MVC 2.0 model binder.
The created instances include a foreign key to an associated model. The created instance does not include an instance of the associated model. I'd like to populate the associated model based on the foreign key. What is the best way to do this?

How I could do it like this... but it seems pretty bad.

foreach (var walker in viewModel.Reservation.Walkers)
{
    if (walker.OptionID != 0 && walkerOption == null)
            walker.Option =
                context.Options.Single(opt => opt.OptionID == walker.OptionID);
}