Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Entity Framework Model & WCF (Saving a Record)

Posted on 2011-09-06
4
857 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

856 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