ASP.NET MVC NHibernate Model Binding

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?

+5
source share
2 answers

It is recommended to use models with a reduced overview, specially designed for your ideas; You can simplify the display operations required by AutoMapper .

+7
source

, , Nhibernate , , , - .

CustomerID Customer, , , Customer. , , .

+4

All Articles