using System.Collections.Generic;
public static void Main()
""customer_type_id"": 645,
""covered_patient_type"": ""Outpatient"",
""expectation"": ""filtered out""
""customer_type_id"": 645,
""covered_patient_type"": ""Inpatient"",
""expectation"": ""filtered out""
""customer_type_id"": 64501,
""covered_patient_type"": ""Outpatient"",
""expectation"": ""filtered out""
""customer_type_id"": 64501,
""covered_patient_type"": ""Inpatient"",
""expectation"": ""selected""
""customer_type_id"": 64501,
""covered_patient_type"": ""Outpatient"",
""expectation"": ""filtered out""
""customer_type_id"": 64501,
""covered_patient_type"": ""Inpatient"",
""expectation"": ""selected""
""customer_type_id"": 64501,
""covered_patient_type"": ""Outpatient"",
""expectation"": ""filtered out""
System.Data.DataTable dt = Newtonsoft.Json.JsonConvert.DeserializeObject<System.Data.DataTable>(json);
System.Data.DataView dvOrg = new System.Data.DataView(dt);
foreach(System.Data.DataColumn column in dt.Columns)
Console.WriteLine($"{column.ColumnName}: {column.DataType}");
Console.WriteLine("Filter By one column: customer_type_id='64501'");
var filterResult = dvOrg.Table.Select("customer_type_id='64501'", "id DESC");
foreach(var row in filterResult)
Console.WriteLine($"ID:{row["id"]}, expectation:{row["expectation"]}, customer_type_id:{row["customer_type_id"]}, covered_patient_type:{row["covered_patient_type"]}");
Console.WriteLine("Filter By two columns: customer_type_id='64501' and covered_patient_type='Inpatient'");
filterResult = dvOrg.Table.Select("customer_type_id='64501' and covered_patient_type='Inpatient'", "id DESC");
foreach(var row in filterResult)
Console.WriteLine($"ID:{row["id"]}, expectation:{row["expectation"]}, customer_type_id:{row["customer_type_id"]}, covered_patient_type:{row["covered_patient_type"]}");
Console.WriteLine("What if covered_patient_type is an enum?");
List<PatientData> data = Newtonsoft.Json.JsonConvert.DeserializeObject<List<PatientData>>(json);
dvOrg = new System.Data.DataView(dt);
foreach(System.Data.DataColumn column in dt.Columns)
Console.WriteLine($"{column.ColumnName}: {column.DataType}");
Console.WriteLine("Filter By one column: customer_type_id='64501'");
filterResult = dvOrg.Table.Select("customer_type_id='64501'", "id DESC");
foreach(var row in filterResult)
Console.WriteLine($"ID:{row["id"]}, expectation:{row["expectation"]}, customer_type_id:{row["customer_type_id"]}, covered_patient_type:{row["covered_patient_type"]}");
Console.WriteLine("Filter By two columns: customer_type_id='64501' and covered_patient_type='Inpatient'");
filterResult = dvOrg.Table.Select("customer_type_id='64501' and covered_patient_type='Inpatient'", "id DESC");
foreach(var row in filterResult)
Console.WriteLine($"ID:{row["id"]}, expectation:{row["expectation"]}, customer_type_id:{row["customer_type_id"]}, covered_patient_type:{row["covered_patient_type"]}");
public int id { get;set; }
public int customer_type_id { get;set; }
public PatientType covered_patient_type { get; set; }
public string expectation { get; set; }
public static class DataListExtensions
public static DataTable ToDataTable<T>(this List<T> items)
DataTable dataTable = new DataTable(typeof(T).Name);
PropertyInfo[] Props = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);
foreach (PropertyInfo prop in Props)
dataTable.Columns.Add(prop.Name);
foreach (T item in items)
var values = new object[Props.Length];
for (int i = 0; i < Props.Length; i++)
values[i] = Props[i].GetValue(item, null);
dataTable.Rows.Add(values);