简体   繁体   English

ASP.NET Core SQL Linq使用字符串列表

[英]ASP.NET Core SQL Linq using list of strings

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: 这是我的linq查询:

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' 无法从“ System.Collections.Generic.List”转换为“ char”

Not sure what that means 不确定那是什么意思

There is a Where statement at the end that has the Contains expression backwards. 在末尾有一个Where语句,它向后Contains表达式。

.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. 这行代码说明: u.Data被视为char[]并且char不能包含列表。

This line of code needs to have the contains flipped around to: 这行代码需要将包含内容翻转到:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM