Wednesday, April 29, 2020

How to convert Json String Value to object


using Newtonsoft.Json.Linq;

Method 1

JArray jArray = JArray.Parse(jsonStringValue);
JObject jObject = (JObject)jArray[0];
var jSonValue = jObject.ToString();

Method 2

var object = JsonConvert.DeserializeObject<dynamic>(jsonDataStringValue);

Saturday, March 14, 2020

Linq Conditional check in where clause


In Linq where clause, include parameter when a value is not NULL, else return the query result.

var qryList = from T1 in Tabel1
              join T2 in Tabel2
              on T1.Id equals T2.Id into grp
              from x in grp
              where T1.Id == ParameterID
              && (!string.IsNullOrEmpty(ParameterName) ? 
                  T1.Name == ParameterName : true)
              select T1.Name;