Click here to Skip to main content
14,742,675 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi ,

I am trying to combine all list of items into one master list items and then want to serialize them into json.

Howerver during that i am getting an error when i try to serialize my list

Quote:
Self referencing loop detected for property 'Call' with type 'BusinessLogic.Linq.Call'. Path '[1][0].Call.Customer.Calls[0].CallLines[0]'.


please suggest

public DataHelper.OperationResult DeleteCallByCallId(int callId, string comments)
        {
            using (var transaction = new TransactionScope())
            {
                try
                {
                    
                    List<object> lstMasterData = new List<object>();
                    //CallSample
                    var callSampleData = (from cs in _db.CallSamples.Where(c => c.IsInActive == false)
                                          join cl in _db.CallLines.Where(c => c.IsInActive == false)
                                          on cs.CallLineID equals cl.CallLineID
                                          where cl.CallID == callId
                                          select cs).ToList();

                    if (callSampleData != null && callSampleData.Count > 0)
                    {
                        lstMasterData.Add(callSampleData);

                        _db.CallSamples.DeleteAllOnSubmit(callSampleData);
                        _db.SubmitChanges();
                    }

                    //CallOrder Deletion
                    var callOrderData = _db.CallOrders.Where(c => c.CallID == callId).ToList();
                    if (callOrderData != null && callOrderData.Count > 0)
                    {
                        lstMasterData.Add(callOrderData);

                        _db.CallOrders.DeleteAllOnSubmit(callOrderData);
                        _db.SubmitChanges();
                    }

                    //Call Attachment
                    var callAttachmentData = _db.CallAttachments.Where(c => c.CallID == callId).ToList();
                    if (callAttachmentData != null && callAttachmentData.Count > 0)
                    {
                        lstMasterData.Add(callAttachmentData);

                        _db.CallAttachments.DeleteAllOnSubmit(callAttachmentData);
                        _db.SubmitChanges();
                    }

                    //Call Product
                    var callProductData = _db.CallLines.Where(c => c.CallID == callId).ToList();
                    if (callProductData != null && callProductData.Count > 0)
                    {
                        lstMasterData.Add(callProductData);

                        _db.CallLines.DeleteAllOnSubmit(callProductData);
                        _db.SubmitChanges();
                    }

                    //Joint Call
                    var jointCallData = _db.JointCalls.Where(c => c.CallID == callId).ToList();
                    if (jointCallData != null && jointCallData.Count > 0)
                    {
                        lstMasterData.Add(jointCallData);

                        _db.JointCalls.DeleteAllOnSubmit(jointCallData);
                        _db.SubmitChanges();
                    }

                    //Call
                    long? diaryId = 0;

                    var data = _db.Calls.Where(c => c.CallID == callId).ToList();

                    if (data != null)
                    {
                        lstMasterData.Add(data);

                        diaryId = data[0].DiaryID;
                        _db.Calls.DeleteAllOnSubmit(data);
                        _db.SubmitChanges();
                    }

                    //Diary data
                    var diaryData = _db.Diaries.Where(d => d.DiaryID == diaryId).ToList();
                    if (diaryData != null)
                    {
                        lstMasterData.Add(diaryData);

                        _db.Diaries.DeleteAllOnSubmit(diaryData);
                        _db.SubmitChanges();
                    }

                    var output = JsonConvert.SerializeObject(lstMasterData);

                    transaction.Complete();
                    return DataHelper.OperationResult.Success;
                }
                catch (Exception ex)
                {
                    return DataHelper.OperationResult.Failed;
                }
            }
        }


What I have tried:

I have tried using ,

JsonConvert.SerializeObject(YourPOCOHere, Formatting.Indented,
new JsonSerializerSettings {
ReferenceLoopHandling = ReferenceLoopHandling.Serialize
});

I am tried this as well

//Call
long? diaryId = 0;

var data = _db.Calls.SingleOrDefault(c => c.CallID == callId);

if (data != null)
{
JsonSerializerSettings jss = new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore };
var result = JsonConvert.SerializeObject(data, Formatting.Indented, jss);
diaryId = data.DiaryID;
_db.Calls.DeleteOnSubmit(data);
_db.SubmitChanges();
}
Posted
Updated 12-Jul-16 17:05pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900