Quantcast
Channel: Web API
Viewing all articles
Browse latest Browse all 4850

REST service returns Json with extra values

$
0
0

Hi all,

I followed a tutorial on creating REST service. Afterwards, I created my own using my edmx model. But when I view the json results, there are extra values which I think gives me the problem of deserializing. Below are codes for more details:

ITransactionRepository:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PTS_Services.Models;

namespace PTS_Services.Models
{
    public interface ITransactionRepository
    {
        IEnumerable<Transaction> GetAll();
    }
}

TransactionRepository:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace PTS_Services.Models
{
    public class TransactionRepository : ITransactionRepository
    {
        private PTSEntities db = new PTSEntities();

        public IEnumerable<Transaction> GetAll()
        {
            return db.Transactions.ToList();
        }
    }
}

TransactionController:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using PTS_Services.Models;

namespace PTS_Services.Controllers
{
    public class TransactionController : ApiController
    {
        static readonly ITransactionRepository repository = new TransactionRepository();

        public IEnumerable<Transaction> GetAllTransactions()
        {
            return repository.GetAll();
        }

    }
}


Results:

[{"$id":"1","ID":1,"EmpID":"00001 ","EDate":"2014-10-10T00:00:00","TimeStart":"12:00 MN","TimeEnd":"12:00 MN","Venue":"Test Venue","Category":"TEST","Type":"Test Meeting Code","Particular":"Test Particular","WholeDay":true,"NoHrs":8.0,"Notes":"Test transaction","EntityKey":{"$id":"2","EntitySetName":"Transactions","EntityContainerName":"PTSEntities","EntityKeyValues":[{"Key":"ID","Type":"System.Int32","Value":"1"}]}},{"$id":"3","ID":2,"EmpID":"00001 ","EDate":"2014-10-10T00:00:00","TimeStart":"12:00 MN","TimeEnd":"12:00 MN","Venue":"Test Venue","Category":"TEST","Type":"Test Meeting Code","Particular":"Test 2","WholeDay":false,"NoHrs":0.0,"Notes":"Test 2","EntityKey":{"$id":"4","EntitySetName":"Transactions","EntityContainerName":"PTSEntities","EntityKeyValues":[{"Key":"ID","Type":"System.Int32","Value":"2"}]}}]

I want to retrieve data from my fields which are from "ID" up to "Notes" only.

 


Viewing all articles
Browse latest Browse all 4850


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>