Mon projet actuel suivant « unité de travail » conception pattern.I ont deux tables like--boucle d'auto-référencement cadre Entité détectée dans l'unité de modèle de travail
où MAINSCHMSTID est la clé étrangère dans la table de détail .Lorsque je suis mise à jour table.i reçois des données avant savechanges comme this--
Ma mise à jour de code Méthode:
public void Update(TEntity entity)
{
db.Entry<TEntity>(entity).State = EntityState.Modified;
}
avis que avec MAINSCHMSTID 1, je reçois c'est l'objet (MAINTENANCESCHMASTER) also.In MAINTENANCESCHMASTER il y a un objet MAINTENANCESCHDETAIL et cette boucle de référencement auto va on.Finally cela ne pas enregistrer le data.It donne une alerte java script:
Dans la console -
J'ai suivi Entity framework self referencing loop detected. Mais n'obtenant aucun résultat.Peut-on suggérer quoi faire?
EDIT:
En AngularJS Controller ma méthode d'édition -
function save() {
scope.submitted = true;
if (scope.maintenanceForm.$valid) {
var result = null;
var operation = null;
if (scope.isEdit) {
operation = "edit";
scope.maintenance.MAINTENANCESCHDETAILS = scope.maintenance.maintenanceItemList;
result = maintenanceService.edit(scope.maintenance);
}
else {
operation = "save";
scope.maintenance.MAINTENANCESCHDETAILS = scope.maintenance.maintenanceItemList;
result = maintenanceService.save(scope.maintenance);
}
result.then(function (data) {
if (data == "") {
alert("Maintenance Schedule Item Already Exist");
initialize();
}
else {
alert("saved successfully");
if (!scope.isEdit) {
scope.maintenance.MAINSCHMSTID = data.ID;
}
convertSvc.updateCollection(scope.maintenanceViews, scope.maintenance, operation, "MAINSCHMSTID");
initialize();
}
}, function (e) {
alert(e);
});
}
}
Server Error in '/' Application.
A circular reference was detected while serializing an object of type 'VMS.DATA.MAINTENANCESCHMASTER'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: A circular reference was detected while serializing an object of type 'VMS.DATA.MAINTENANCESCHMASTER'.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[InvalidOperationException: A circular reference was detected while serializing an object of type 'VMS.DATA.MAINTENANCESCHMASTER'.]
System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +2533 System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +371 System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +778
System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +2751 System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +371 System.Web.Script.Serialization.JavaScriptSerializer.SerializeEnumerable(IEnumerable enumerable, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +186
System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +2699 System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +371 System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +778
System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +2751 System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +371 System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, StringBuilder output, SerializationFormat serializationFormat) +57 System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, SerializationFormat serializationFormat) +83
System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj) +44 System.Web.Mvc.JsonResult.ExecuteResult(ControllerContext context) +817
System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +39
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +116
1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +529
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList1 filters, ActionResult actionResult) +106
1.CallEndDelegate(IAsyncResult asyncResult) +42
System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +321 System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +185
System.Web.Mvc.Async.WrappedAsyncResult
System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +133
1.CallEndDelegate(IAsyncResult asyncResult) +70
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +40
System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +34
System.Web.Mvc.Async.WrappedAsyncVoid
System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +133
1.CallEndDelegate(IAsyncResult asyncResult) +62
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +37
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +44 System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +39
System.Web.Mvc.Async.WrappedAsyncVoid
System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +133
1.CallEndDelegate(IAsyncResult asyncResult) +70
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +37 System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +39
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +39
System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +39
System.Web.Mvc.Async.WrappedAsyncVoid
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +133
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +37
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +40 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9644037 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1055.0
Dans Global.asax.cs--
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
HttpConfiguration config = GlobalConfiguration.Configuration;
config.Formatters.JsonFormatter
.SerializerSettings
.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
}
Que voulez-vous ** faire du code? Qu'est-ce que ** fait ** réellement? Est-ce qu'il lance des exceptions? – mjwills
Je veux qu'il ne montrera aucune erreur, sauvera le maître et le détail table.it ne jette aucune exception. Montrant seulement une alerte de manuscrit de Java d'erreur. –
je édite ma question. Vous pouvez voir l'erreur. –