English 中文(简体)
Castle MonoRail ARDataBind trying to bind to non-existent row
原标题:

I have a shopping cart application running on MonoRail and using Castle ActiveRecord/NHibernate, and there is a ShoppingCart table and a ShoppingCartItems table, which are mapped to entities.

Here s the scenario: a user adds things to the shopping cart, say 5 items, and goes to view the cart. The cart shows all 5 items. the user duplicates the tab/window and gets another tab of the same cart (call it tab B). the user removes an item from the cart, so now there are 4 items in tab B, but in the original tab A, there are still 5 items. the user goes back to tab A, and updates something in the cart and clicks the "update" button which submits the changes. my MonoRail action tries to do an ARDataBind on ShoppingCartItems using the data from the view, which includes all 5 items. when it gets to the item that the user deleted from tab B, it throws a "No row with the given identifier exists" for that item.

I can t figure out if there is a way to have it not bind that row, return null, return new instance, etc.? there is an AutoLoadBehavior parameter on the ARDataBind attribute, but that appears to only affect loading of child entities, and not the root entity. regardless of which option I choose, I get the exception before control even enters the action method (except AutoLoadBehavior.Never, but that doesn t really help me).

instead, I have code that calls Request.ObtainParamsNode() to pull the form nodes and parse them manually into objects, and ignores the ones that no longer exist. is there a better way?

thanks.

最佳回答

Inherit ARDataBinder, override FindByPrimaryKey(Type targetType, object id):

protected override object FindByPrimaryKey(Type targetType, object id) {
  return FindByPrimaryKey(targetType, id, false);
}

The key here is the false parameter, which makes it return null instead of throwing.

Then inherit ARDataBindAttribute, override the CreateBinder() method and make it return your new binder instead of the default ARDataBinder.

Then apply your custom binder attribute instead of ARDataBindAttribute.

问题回答

暂无回答




相关问题
Many-To-Many Surrogate Key problem. Please help!

I have a many-to-many relationship with surrogate key The classes are: Insurer - InsurerSection - Section. InsurerSection has one extra attribute: active : bool. How do I access these bool ...

hql get objects where certain property is unique

I am trying to perform an hql query which returns a list of objects with distinct property value. Following is my pseudo code: string hql = @"select distinct m from Merchandise m where ...

nhibernate hql subquery performance

I have written an hql to support paging string hql = @"select distinct mr from MediaResource as mr where mr.Deleted= false ...

ASP.NET MVC - Castle ActiveRecord - Show SQL queries

I m using ASP.NET MVC with Castle ActiveRecord as my persistance layer. I want to know if it s possible to show the SQL queries being executed on my MySQL server. I know it s possible in a Web ...

热门标签