dynamic-linq-query-builder
dynamic-linq-query-builder copied to clipboard
Dynamic type problem
Hi all, how can I execute dynamic query on DynamicObject array?
this work (with anonymous object)
var quarableList = new[] { new { TypeName = "PROCESS.ITEM.END" } }.ToList().AsQueryable();
var resr = quarableList.BuildQuery(testRule).ToList();
but this doen't :(
var data = @"{
'Id': 999,
'ParentId': null,
'TypeName': 'PROCESS.ITEM.END',
'Name': 'END'
}";
var testRule = new FilterRule
{
Condition = "and",
Field = "TypeName",
Id = "Id",
Input = "NA",
Operator = "equal",
Type = "string",
Value = "PROCESS.ITEM.END",
};
var expObjData = JsonConvert.DeserializeObject<dynamic>(data);
var quarableList = new[] { expObjData }.ToList().AsQueryable();
var resr = quarableList.BuildQuery(testRule).ToList();
Thanks, Best Regards,
Hi @tghamm , @cbrianball , @willydavidjr , @elialgranti , I found a solution and wrote it on my fork and commit. Do you think it is suitable ?
https://github.com/MasallahOZEN/dynamic-linq-query-builder/commits/master
Best regards,
Hi again @tghamm , @cbrianball , @willydavidjr , @elialgranti , I found a new solution and commit. Do you think it is suitable ?
https://github.com/MasallahOZEN/dynamic-linq-query-builder/commit/985c3ec775bf88ce3cee015698509de1543d16ce
//Json string model var dataItem = @"{ 'Id': 999, 'PersonImsId': 123, 'CreatorImsId': 123 }";
//typed model
var boundRefDataItem = new BoundedReferenceDataActionItem
{
FormId = 1,
Mode = 1,
ComponentId = 12,
StateId = 1
};
//=> ExpandoField = generated from dataItem.
//Adding new field to dataItem model
ExpandoField.Add("FirstName", "Masallah");
ExpandoField.Add("LastName", "ÖZEN");
ExpandoField.Add("Age", 36);
//Add new complex type to typed model
boundRefDataItem.DataItem = ExpandoField;
//Submodel filtering
var rule = new FilterRule
{
Field = "DataItem.Age",
Id = "FirstName",
Input = "NA",
Operator = "greater_or_equal",
Type = "integer",
Value = "36"
};
Thnx Best Regards,
Hey, sorry for the slow response @MasallahOZEN . I'd be open to some of your changes if you wanted to lay out what they accomplish and submit PRs. Thanks!