none
Json data from Linq RRS feed

  • Question

  • I am trying to create JSON data, but when I run this code I get the following error.

    "LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression."

    How can I fix this?

    SALES_NUMBER and SHIPMENT_NUMBER are both decimal type.

    var jsonData = new
                {
                    total = totalOrders / gridSettings.PageSize + 1,
                    page = gridSettings.PageIndex,
                    records = totalOrders,

                    rows = (
                        from c in openOrders
                        select new
                        {
                            id = c.ID,
                            cell = new[] { c.SALES_NUMBER.ToString(), c.SHIPMENT_NUMBER.ToString(), c.CUSTOMER_NAME }
                        }).ToArray()

                };

    Thanks you


    Peter

    Friday, October 12, 2012 3:08 PM

Answers

  • I have found the answer.

             var jsonData = new

                {
                    total = totalOrders / gridSettings.PageSize + 1,
                    page = gridSettings.PageIndex,
                    records = totalOrders,

                    rows = (
                    from c in openOrders
                    select new
                    {
                        c.ID, 
                        c.SALES_NUMBER,
                        c.SHIPMENT_NUMBER,
                        c.CUSTOMER_NAME
                    })

                };


    Peter

    • Marked as answer by pczurak Friday, October 12, 2012 6:18 PM
    Friday, October 12, 2012 6:18 PM

All replies

  • I have found the answer.

             var jsonData = new

                {
                    total = totalOrders / gridSettings.PageSize + 1,
                    page = gridSettings.PageIndex,
                    records = totalOrders,

                    rows = (
                    from c in openOrders
                    select new
                    {
                        c.ID, 
                        c.SALES_NUMBER,
                        c.SHIPMENT_NUMBER,
                        c.CUSTOMER_NAME
                    })

                };


    Peter

    • Marked as answer by pczurak Friday, October 12, 2012 6:18 PM
    Friday, October 12, 2012 6:18 PM
  • Hi pczurak,

    I'm glad to hear that you have solved the issue, and thanks for your sharing.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Monday, October 15, 2012 1:42 AM
    Moderator