JavaScriptSerializer().Serialize(Entity Framework object)

Posted by loviji on Stack Overflow See other posts from Stack Overflow or by loviji
Published on 2010-03-15T19:46:21Z Indexed on 2010/03/15 19:49 UTC
Read the original article Hit count: 1148

Filed under:
|

May be, it is not so problematic for you. but i'm trying first time with json serialization. and also read other articles in stackowerflow.

I have created Entity Framework data model. then by method get all data from object:

private uqsEntities _db = new uqsEntities();
//get all data from table sysMainTableColumns where tableName=paramtableName
public List<sysMainTableColumns> getDataAboutMainTable(string tableName)
{
     return (from column in _db.sysMainTableColumns
                    where column.TableName==tableName
                    select column).ToList();

}

my webservice:

public string getDataAboutMainTable()
{
    penta.DAC.Tables dictTable = new penta.DAC.Tables();
    var result = dictTable.getDataAboutMainTable("1");
    return new JavaScriptSerializer().Serialize(result);
}

and jQuery ajax method

$('#loadData').click(function() {
            $.ajax({
                type: "POST",
                url: "WS/ConstructorWS.asmx/getDataAboutMainTable",
                data: "{}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(msg) {
                    $("#jsonResponse").html(msg);

                    var data = eval("(" + msg + ")");
                    //do something with data
                },
                error: function(msg) {

                }
            });
        });

problem with data, code fails there. and i think i'm not use JavaScriptSerializer().Serialize() method very well.

Please, tell me, what a big mistake I made in C# code?

© Stack Overflow or respective owner

Related posts about c#

Related posts about entity-framework