Last post Oct 28, 2015 11:22 PM by Candice Zhou
Oct 27, 2015 03:45 PM|Kapils573|LINK
Hello Everyone ,
I am new to LINQ to SQL and trying to write Between condition in a where Clause. Does not return anything Please advice where the problem is
for (int i = 0; i < filters.Count; i++)
if (filters[i].FilterItem != null && filters[i].FilterItem != "")
vSql = vSql.Where(filters[i].FilterItem.StartsWith(filters[i].FilterStartRange) + " && " + filters[i].FilterItem.EndsWith(filters[i].FilterEndRange));
Oct 27, 2015 04:07 PM|Rion Williams|LINK
If you are building actual SQL itself, then you won't want to use the '&&' operator as that is a C# specific operator. You would instead use 'AND' :
vSql = vSql.Where(filters[i].FilterItem.StartsWith(filters[i].FilterStartRange) + " AND " + filters[i].FilterItem.EndsWith(filters[i].FilterEndRange));
However I'm not entirely sure what vSql is in this context. Is this some type of custom object? A collection? If you can expand a bit more on exactly your Filters look like, what your variables refer to, etc.
Oct 28, 2015 09:01 AM|Kapils573|LINK
I tried using the AND operator but the query did not return anything. Here vSQL is IQueryable<InventoryItem> where InventoryItem is the name of the table in database.
Here filters[i].FilterItem is the name of columns from the InventoryItem selected dynamically and filters[i].FilterStartRange & filters[i].FilterEndRange are the values passed.
Oct 28, 2015 11:22 PM|Candice Zhou|LINK
Here vSQL is IQueryable<InventoryItem> where InventoryItem is the name of the table in database.
You should use Lambda .Where() expression to return selected/flagged objects:
vSql.Where(); //write Lambda expression here