In Entity Framework 6 this query would run fine. EF6 supports SQL translation of StartsWith and it supports using local sequences (letters) in a query expression.
EF core 3 (the version in the question as the exception message indicates) also supports SQL translation of StartsWith. The problem here (which the other answer misses completely) is that the local sequence is used in a way that's not supported. A query like...
var results = db.Carriers.AsNoTracking()
.Where(c => letters.Contains(c.Name))
.ToList();
...would be supported because letters can simply be translated into an IN clause. But of course that's an entirely different query.
Using letters.Any requires EF to convert letters into "something" that can be joined with in SQL. EF6 does this by building a result set in the SQL query:
WHERE EXISTS (SELECT
1 AS [C1]
FROM (SELECT
N'A' AS [C1]
FROM ( SELECT 1 AS X ) AS [SingleRowTable1]
UNION ALL
SELECT
N'B' AS [C1]
FROM ( SELECT 1 AS X ) AS [SingleRowTable2]
UNION ALL
SELECT
N'C' AS [C1]
FROM ( SELECT 1 AS X ) AS [SingleRowTable3]) AS [UnionAll2]
WHERE ( CAST(CHARINDEX([UnionAll2].[C1], [Extent1].[Name]) AS int)) = 1
Which works, but isn't scalable at all. EF core 3 doesn't support it and there's no easy work-around as suggested in the other answer.
A possible work-around is to build a predicate with || (Or) predicates, for example:
var pred = letters.Aggregate(PredicateBuilder.False<Carrier>(),
(p,x) => p = p.Or(c => c.Name.StartsWith(x)));
var results = db.Carriers.AsNoTracking()
.Where(pred)
.ToList();
Where PredicateBuilder is a predicate builder like Linqkit or this one. But this method isn't scalable either. EF creates a parameter for each entry in letters, so you may hit the 2100-parameters threshold in Sql Server.
c.Name.Substring(0, val.Length).Equals(val)- iSR5.Where(c => letters.Contains(c.Name[0].ToString()))- Alexander Petrovletters.Contains(c.Carrier.Name.Substring(0, 1)which appears to work. The catch is that it will only work with 1 letter, and doesn't have the flexibility of StartsWith - MDave