I’m trying to recreate some SQL queries I have into L2E statements. One of the queries is:
SELECT TOP 25 itms.[StringValue]
,itms.[Name]
,itms.[Picture]
FROM [DB].[dbo].[Items] AS itms
WHERE itms.StringValue LIKE '[A-G]%'
I am given a start char (A in this case) and an end char (G) and I need to pull all of the items whos StringValue starts with a char between Start and Finish.
My first try was to see if L2E would just give it to me with this query:
items = from i in items
where i.StringValue.StartsWith("[" + refinement.Value + "]")
select i;
I figured it wouldn’t work, but it was worth a try.
Couple of options that should work:
1) if you know the filter is just based on the first char, then you could do something like:
similarly, you could fetch the first char and just do the greater/lesser checks in the Where clause (if it’s always a range like that)
2) if you want, you can still use sql to query with L2E, just use the ExecuteStoreQuery and let it return the entities back for you:
http://msdn.microsoft.com/en-us/library/dd487208.aspx
If you want the returned entities to be tracked, make sure to call the overload that lets you specify the entity set name:
http://msdn.microsoft.com/en-us/library/dd487226.aspx