dynamic-linq-query-builder
dynamic-linq-query-builder copied to clipboard
Using complex Any() conditions
Hi. How can I write such a thing?
var Orders = new List<Order>()
{
new Order{
OrderId =1,
CreationTime = DateTime.Now,
ProductProviderType = "DomesticFlight"
},
new Order{
OrderId =2,
CreationTime = DateTime.Now,
ProductProviderType = "InternationalFlight"
},
new Order
{
OrderId =3,
CreationTime = DateTime.Now,
ProductProviderType = "Manuel"
},
new Order
{
OrderId =4,
CreationTime = DateTime.Now,
ProductProviderType = "Hotel"
}
};
var hasOffer = Orders.Any(p => p.ProductProviderType == "Hotel") && Orders.Any(p => p.ProductProviderType == "DomesticFlight" || p.ProductProviderType == "InternationalFlight");
I have written something like that but it doesn't have any output :
var myFilter = new QueryBuilderFilterRule()
{
Condition = "AND",
Rules = new List<QueryBuilderFilterRule>()
{
new QueryBuilderFilterRule
{
Field = "ProductProviderType",
Id = "1",
Input = "text",
Operator = "in",
Type = "string",
Value = new [] { "Hotel" }
},
new QueryBuilderFilterRule()
{
Condition = "OR",
Rules = new List<QueryBuilderFilterRule>
{
new QueryBuilderFilterRule
{
Field = "ProductProviderType",
Id = "2",
Input = "text",
Operator = "in",
Type = "string",
Value = new [] { "InternationalFlight" }
},
new QueryBuilderFilterRule
{
Field = "ProductProviderType",
Id = "2",
Input = "text",
Operator = "in",
Type = "string",
Value = new [] { "DomesticFlight" }
},
},
}
}
};
Id value should be same as Field in your case:
Field = "ProductProviderType", Id = "ProductProviderType",
If the ProductProviderType was a collection of objects, Id value would be different from FIeld:
Field = "ProductProviderType.Prop1Name", Id = "Prop1Name",
I hope this answers your question.