I am trying to incorporate the LINQ equivalent of this SQL query. The database is SQL Server.
SELECT * FROM Party
WHERE Partyname LIKE '[a-m]%z'
This query will return all the records where the partyname column can start with any letter between a - m and must end with the letter z.
If I wanted to do a LINQ equivalent, how can I do this? I tried to do this in this fashion, but clearly there is a better way.
Parties.Where(p => (p.Partyname.StartsWith("a") || p.Partyname.StartsWith("b") ||
p.Partyname.StartsWith("c")) && p.Partyname.EndsWith("Z"))
.Select(x => new { x.Party_id, x.Partyname, x.Party_no, x.Reference, x.Input_dt })
Note: Linqpad pluralizes the name of the table.