Here is my code:-
Repository.DB.Table01Repository.AsQueryable().Where(item => (item.Name.Split(' ')[1] == null)).ForEach(items => _VerifyList.Add(items.Name.Trim()));
I split ‘Name’ by ‘ ‘ and if it does not have second element, I need those records.
Thanks..
Since
Splitwill produce two or more elements if theNamecontains at least one space, you can write it as follows:There’s no need to actually perform the
Split.In addition,
Containscan be mapped to SQL (it is one of the CLR methods that map to canonical LINQ functions) which means that the query will execute successfully on your database. Other methods (likeSplititself) cannot be used when querying a database throughIQueryable, and would cause a runtime exception to be thrown.