I have a table set up like so:
prefix | value
ABC 1234
ABC 5678
DEF 1234
Is it possible to create a linq query where prefix and value are concatenated for comparison in the where clause? I’ve tried this, but it always returns an empty set:
selected =
from i in dc.items
where i.prefix + i.value == "ABC1234"
select i;
Edit: the following T-SQL comes up with the correct results:
WHERE LTRIM(RTRIM([prefix])) + LTRIM(RTRIM([value])) = 'ABC1234'
Edit2: The following, which combines most of the answers below, still does not work:
where (String.Concat(i.prefix.Trim(), i.value.Trim())) == "ABC1234"
Edit3: So I’ve got it working, but I have no clue why. I’ve accepted an answer but if someone posts why it works I’d be grateful 🙂
This works (returns n rows):
var temp = dc.items.Where(i => i.prefix.Trim() + i.prefix.Trim() == "ABC1234");
This does not work (returns 0 rows):
var temp =
from i in dc.items
where i.prefix.Trim() + i.value.Trim() == "ABC1234"
select i;
I dont’s speak english. Try this: