Created
September 6, 2017 05:16
-
-
Save anonymous/a408f6bf4fb5637207b92e859e76f0e9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Newtonsoft.Json; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace ConsoleApp4 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var students = GetEntities<SAStudent>(); | |
} | |
public static List<T> GetEntities<T>() | |
{ | |
var odataResponse = "{\"@odata.context\":\"http://localhost:8002/Sample/Sample/OData/$metadata#SAStudent(Id)\",\"value\":[{\"Id\":\"NIYOZO\"},{\"Id\":\"E2E18\"},{\"Id\":\"E2E24\"},{\"Id\":\"E2E7\"},{\"Id\":\"E2E29\"},{\"Id\":\"E2E22\"},{\"Id\":\"E2E15\"},{\"Id\":\"E2E13\"},{\"Id\":\"E2E5\"},{\"Id\":\"E2E21\"},{\"Id\":\"E2E28\"},{\"Id\":\"DILQOS\"},{\"Id\":\"TESTA\"},{\"Id\":\"E2E8\"},{\"Id\":\"NIYDIL\"},{\"Id\":\"JABDIL\"},{\"Id\":\"E2E1\"},{\"Id\":\"E2E20\"},{\"Id\":\"E2E17\"},{\"Id\":\"E2E27\"},{\"Id\":\"JURA\"},{\"Id\":\"E2E10\"},{\"Id\":\"HUSKAR\"},{\"Id\":\"E2E26\"},{\"Id\":\"E2E2\"},{\"Id\":\"FREKEN\"},{\"Id\":\"E2E23\"},{\"Id\":\"E2E16\"},{\"Id\":\"TESTB\"},{\"Id\":\"VARJAM\"},{\"Id\":\"E2E30\"},{\"Id\":\"NIYJAN\"}]}"; | |
JsonSerializerSettings settings = new JsonSerializerSettings() { ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor, MetadataPropertyHandling = MetadataPropertyHandling.Ignore }; | |
var result = JsonConvert.DeserializeObject<OData<T>>(odataResponse, settings); | |
var list = result.Value as List<T>; | |
return list; | |
} | |
} | |
public partial class SAStudent | |
{ | |
private string id; | |
public string Id | |
{ | |
get { return id; } | |
set { id = value; } | |
} | |
private string name; | |
public string Name | |
{ | |
get { return name; } | |
set { name = value; } | |
} | |
} | |
public class OData<T> | |
{ | |
[JsonProperty("odata.metadata")] | |
public string Metadata { get; set; } | |
public List<T> Value { get; set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment