N
NvrBst
I have an List/Array of strings and I want to query the database with
only items that start with a value in the List/Array. Example:
List<string> test1 = new List<string>() { "T", "B", "F" };
....
var myQuery = from i in myDB.myTables
where i.VALUE.StartsWith(test1[0]) || i.VALUE.StartsWith(test1[1])
|| i.VALUE.StartsWith(test1[2])
select i;
Problem: The List/Array (test1) is variable size and only available
at runtime.
What I attempted:
1. Extention Methods: where "SpecialStartsWith()" loops through test1
and returns true only if it is in the list.
var myQuery = from i in myDB.myTables
where i.VALUE.SpecialStartsWith()
select i;
Problem: I get a "SpecialStartsWith can't be translated to a SQL
Query" exception.
2. Trying to build the IQueryable with multiple Assignments:
IQueryable<myTable> total;
IQueryable<myTable> current;
foreach(string A in test1) {
current = from i in myDB.myTables
where i.VALUE.StartsWith(A)
select i;
total.Union(current);
}
Problem: current gets reset each time it is called; doesn't append.
Is there a way for me to Build a single query from all the strings in
an array (that start with)? Or am I going to have to perform a bunch
of query's and just dump each query into a List?
Thanks. The last dumping to a table works fine for me, this just
seemed like something I should be able to do but I haven't figured it
out *more so for future reference*.
only items that start with a value in the List/Array. Example:
List<string> test1 = new List<string>() { "T", "B", "F" };
....
var myQuery = from i in myDB.myTables
where i.VALUE.StartsWith(test1[0]) || i.VALUE.StartsWith(test1[1])
|| i.VALUE.StartsWith(test1[2])
select i;
Problem: The List/Array (test1) is variable size and only available
at runtime.
What I attempted:
1. Extention Methods: where "SpecialStartsWith()" loops through test1
and returns true only if it is in the list.
var myQuery = from i in myDB.myTables
where i.VALUE.SpecialStartsWith()
select i;
Problem: I get a "SpecialStartsWith can't be translated to a SQL
Query" exception.
2. Trying to build the IQueryable with multiple Assignments:
IQueryable<myTable> total;
IQueryable<myTable> current;
foreach(string A in test1) {
current = from i in myDB.myTables
where i.VALUE.StartsWith(A)
select i;
total.Union(current);
}
Problem: current gets reset each time it is called; doesn't append.
Is there a way for me to Build a single query from all the strings in
an array (that start with)? Or am I going to have to perform a bunch
of query's and just dump each query into a List?
Thanks. The last dumping to a table works fine for me, this just
seemed like something I should be able to do but I haven't figured it
out *more so for future reference*.