Solved

Entity Framework Model & WCF (Saving a Record)

Posted on 2011-09-06
4
852 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
ID: 36487433
0
 

Accepted Solution

by:
Dinesh Kumar earned 0 total points
ID: 36487793
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
ID: 37909725
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

776 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