クライアント タイプのエンティティを更新したいと思います。
[HttpPost]
public ActionResult Manage(String id, FormCollection collection)
{
// Create service
ClientService service = new ClientService();
// Read existing client
Client c = service.FindByUsername(id);
// Update client by using values from submitted form collection
UpdateModel(c, "Client");
service.Update(c);
return View(c);
}
サービスは、クライアント タイプのエンティティを返します。クライアントには次のプロパティがあります: Username、FirstName、LastName、Id - これらは送信されたコレクションのキーです。
さらに、クライアント エンティティには、注文のリスト (SQL Metal によって追加されたもの) と、オブジェクト追跡用のバージョン フィールドがあります。
UpdateModel 行がヒットしてもエラーにはなりませんが、オブジェクト c の値は更新されません。問題はservice.Update(c)
ではなく にありUpdateModel(c, "Client")
ます。
私は何を間違っていますか?
ありがとうございました
編集: クライアントは SQL メタルによってマップされます。
その属性は次のとおりです。
- 整数 ID
- 文字列のユーザー名。
- 文字列名;
- 文字列 姓;
- タイムスタンプのバージョン
- IQuerable 注文;
エラー (内部例外は null)
System.InvalidOperationException was unhandled by user code
Message=The model of type 'Shop.MVC.Data.Client' could not be updated.
Source=System.Web.Mvc
StackTrace:
at System.Web.Mvc.Controller.UpdateModel[TModel](TModel model, String prefix, String[] includeProperties, String[] excludeProperties, IValueProvider valueProvider)
at System.Web.Mvc.Controller.UpdateModel[TModel](TModel model)
at Shop.MVC.Web.Controllers.ClientController.Manage(String id, FormCollection collection) in C:\Codebox\ARE002\VideoPlayerPrototype\Shop.MVC.Web\Controllers\ClientController.cs:line 45
at lambda_method(Closure , ControllerBase , Object[] )
at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
InnerException: