I am trying to implement a method where the keywords stored in the database for an activity (split by a comma) match the giving string split by a comma.
publ
LINQ to Entities tries to translate your LINQ query into SQL. Since it doesn't know how to do String.Split
in a SQL query, it fails.
This means that unless you want to write a SQL implementation of String.Split
, you can only do it in LINQ to objects, which means you need to load all of your data into memory first, then do the where
clause. One easy way to do this is using .ToList()
:
var results = (from a in Entities.TblActivities select a).ToList(); //Results are now in memory
results = results.Where(a =>
a.Keywords.Split(',').Any(p => keyword.Contains(p))).ToList(); //This uses LINQ-to-objects