0

I have a list of strings like this

list = {a,b,c}

I would like to compare it in the database but I'm not sure how to go about doing that. This is my linq query:

var initialData = (from item in dbContext.DocumentCategories
    join df in dbContext.DocumentFields
    on item.Id equals df.DocumentCategoriesId
    join dfs in dbContext.DocumentFieldsStore
    on df.Id equals dfs.DocumentFieldsId
    select new SearchDocumentsListViewModel
    {
        CategoryId = item.Id,
        DocumentId = dfs.DocumentsId,
        FieldId = df.Id,
        Data = dfs.Data
    })
    .ToList();

initialData = initialData
    .Where(u => u.Data.Contains(list))
    .ToList();

Currently its showing me this error:

cannot convert from 'System.Collections.Generic.List' to 'char'

Not sure what that means

4
  • 1
    Should the Where at the end be flipped to .Where(u => list.Contains(u.Data))? Seems like data might be a string. Commented Dec 8, 2018 at 3:38
  • Looks like it works. But why is that? Commented Dec 8, 2018 at 3:40
  • 1
    Because you were asking the question of "Does your string contain the list?" instead of "Does your list contain the string" Commented Dec 8, 2018 at 3:42
  • Thank you! I understand it now. Do you want to put it in an answer Commented Dec 8, 2018 at 3:44

1 Answer 1

2

There is a Where statement at the end that has the Contains expression backwards.

.Where(u => u.Data.Contains(list)

This line of code explained: u.Data is being treated as a char[] and a char cannot contain a list.

This line of code needs to have the contains flipped around to:

.Where(u => list.Contains(u.Data)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.