Solved

Entity Framework Model & WCF (Saving a Record)

Posted on 2011-09-06
4
841 Views
Last Modified: 2012-05-12
I  am trying to convert JsonData into the object to save it into the database table using Entity framework model using the attached code. but ends up with the following error:

The type 'XXX"  cannot be serialized to JSON because its IsReference setting is 'True'. The JSON format does not support references because there is no standardized format for representing references. To enable serialization, disable the IsReference setting on the type or an appropriate parent class of the type.

The tableNameListData is:
String tableNameListData ="\"badges\":\"1\",\"notifications\":\"1\",\"sounds\":\"1\"}";

I am calling the attached code function in the following way:

  public string AddToTableNameList(string tableNameListData)
        {
            tableName ed = Deserialize<tablename>(tableNameListData); [Here isreference error comes]
            ----
            ---
        }

 
Please help!
public static T Deserialize<T>(string json) //
        {
            T obj = Activator.CreateInstance<T>();
            MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(json));
            DataContractJsonSerializer serializer = new DataContractJsonSerializer(obj.GetType());
            obj = (T)serializer.ReadObject(ms);
            ms.Close();
            return obj;
        }

Open in new window

0
Comment
Question by:Dinesh Kumar
4 Comments
 
LVL 15

Expert Comment

by:Minh Võ Công
Comment Utility
0
 

Accepted Solution

by:
Dinesh Kumar earned 0 total points
Comment Utility
In wcf method I wrote:
tableName objw = new tableName();    
JavaScriptSerializer serializer = new JavaScriptSerializer();  
objw = serializer.Deserialize<tableName>(tableJsonData);    


and i called it this way i.e modified the input data as follows:

String tableJsonData="{\"badges\":\"true\",\"notifications\":\"true\",\"sounds\":\"true\"}";

so if it is having corresponding int in the database table then the value say
\"id\":\"value\"
value should be integer e.g 4 or 5 etc. and not like 'din'

this way I was able to solve the issue.

also note true is not equal to 1 in c# so we need to write true only.

0
 
LVL 19

Expert Comment

by:Amandeep Singh Bhullar
Comment Utility
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now