In NHibernate, I no longer expose foreign keys for my domain objects, so the product no longer has a property:
public int CategoryId {get;set;}
but instead:
public Category Category {get;set;}
Unfortunately, this does not work so well with automatic model binding in ASP.NET MVC - if I just want to bind a collection of forms directly to a domain object.
For example, I could not just select the list of category identifier values in my view, accept the product object in my controller action, and expect MVC to convert it to a category object.
My solution so far has been to create view models that do have properties for foreign key values. However, this usually results in a fair bit of code duplication and additional matching logic in my controller.
Is there a better way?
source
share