これは私のモデルです:
public class StockLine : Keyed
{
/.../
/// <summary>
/// Reference to the delivery note line that created the current stock line.
/// </summary>
[Navigation]
[Display(ResourceType = typeof(Resources.ApplicationResources), Name = "DeliveryNoteLine")]
public virtual DeliveryNoteLine DeliveryNoteLine { get; set; }
}
1 つの StockLine は、対応する DeliveryNoteLine に関連付けることができます。
私が実装したいのは、DeliveryNoteLine を削除するときに、対応する StockLine も削除する必要があるということです。しかし、これをどのように行う可能性があるかはわかりません。
これは私のコントローラーです:
/// <summary>
/// Returns the default Delete view for the TEntity object.
/// </summary>
/// <param name="id">Id of the TEntity object to delete.</param>
/// <returns>Redirection to the Index action if an error occurred, the Delete View otherwise.</returns>
public virtual ActionResult Delete(string id)
{
var request = new RestSharp.RestRequest(Resource + "?id={id}", RestSharp.Method.GET) { RequestFormat = RestSharp.DataFormat.Json }
.AddParameter("id", id, RestSharp.ParameterType.UrlSegment);
var response = Client.Execute(request);
// Deserialize response
var model = DeserializeResponse<TEntity>(response);
HandleResponseErrors(response);
if (Errors.Length == 0)
return View(model);
else
{
ViewBag.Errors = Errors;
return RedirectToAction("Index");
}
}
/// <summary>
/// Handles the POST event for the Delete action.
/// </summary>
/// <param name="id">Id of the TEntity object to delete.</param>
/// <param name="model">TEntity object to delete.</param>
/// <returns>Redirection to the Index action if succeeded, the Delete View otherwise.</returns>
[HttpPost]
public virtual ActionResult Delete(string id, TEntity model)
{
var request = new RestSharp.RestRequest(Resource + "?id={id}", RestSharp.Method.DELETE) { RequestFormat = RestSharp.DataFormat.Json }
.AddParameter("id", id, RestSharp.ParameterType.UrlSegment);
var response = Client.Execute(request);
// Handle response errors
HandleResponseErrors(response);
if (Errors.Length == 0)
return RedirectToAction("Index");
else
{
request = new RestSharp.RestRequest(Resource + "?id={id}", RestSharp.Method.GET) { RequestFormat = RestSharp.DataFormat.Json }
.AddParameter("id", id, RestSharp.ParameterType.UrlSegment);
response = Client.Execute(request);
model = DeserializeResponse<TEntity>(response);
ViewBag.Errors = Errors;
return View(model);
}
}
何か案は??