How to get IEnumerable <Foo> instead of IEnumerable <string> from LINQ?

I am stuck in a LINQ query where I am trying to get list entries back SQL Tablefrom using, EntityFramework 6instead of getting this list, I keep getting IEnumerable<string[]>.

This is what I did to get IEnumerable<string[]>. I have columnin tablewhich to split, and then I check if listthese rows contain : The value in the table column columnOnecan be something like this "a-b"or "b-c"etc., so you need to use thiss.columnOne.Split('-')

list<string> checkList = new list<string>();
checkList.add("a")
checkList.add("b")
checkList.add("c")

List<Foo> fooList = dbContext.Foos.ToList();

IEnumerable<string[]> items = fooList.Select(s => s.columnOne.Split('-'));

var result = items.SelectMany(x => x)
                  .Where(s => checkList.Contains(s)).ToList();

The above works as it should, but at the end it returns a list stringthat is not what I need.

I tried this below:

List<Foo> fooList = dbContext.Foos.ToList();

var test = fooList.Where(s => s.columnOne.Split('-'));

, <Foo>, <string>

, Where bool, fooList.Where(s => s.columnOne == "someString");, , LINQ, , .

.

+6
2

where checkList

var test = fooList.Where(foo => foo.columnOne.Split('-').Any(str => checkList.Contains(str)));
+6
dbContext.Foos
    .ToList()
    .Where(foo => foo.columnOne.Split('-')
        .Any(x => checkList.Contains(x))

, Foo, ToList . , , Linq , where. , .

, Set<string> List<string> checklist, , .

+1

All Articles