Last post Jul 19, 2017 10:52 AM by mgebhard
Jul 19, 2017 09:55 AM|gani7787|LINK
I am passing list value into the datatable.
I want to find the column first and then check whether the value exist or not for that columns.
I want to write in LINQ Query as bool true/false
string str ABSCHECK = ABS A#ABS B // input value
string words1 = str.Split('#'); //Splitting the values
words1 ABS A //list
 ABS B
The above two value is a column name and i want to check in the below table.
For ABS A ==> Matching two columns and values present(like ABS A(MN) and ABS A(MX))
find only MN and MX
For ABS B ==> Matching two columns and values exists (like ABS B(MN) and ABS B(MX)) find only MN and MX
So i want to return result is true.
if nothing is matching, it means (column not identified and value not present) returns false.
How to write LINQ..?
below is my query
bool results = (from r in DTTABLE.AsEnumerable()
select r.Field<string>(words1.ToList())); // to find out columns and value
but not working..?
Jul 19, 2017 10:52 AM|mgebhard|LINK
You need to rethink the design.
You have a relationship where ABS A means retrieve columns ABS A(MN) and ABS A(MX). This mapping information should be stored in a lookup otherwise you'll end up hard coding the mapping.
Your actual question is how to build a dynamic query in linq. To build a dynamic linq query you'll need to use reflection.
Otherwise, you can build a SQL string and invoke the query directly. This is probably the easiest and most straight forward method.