c# - Linq to entities 无法处理 string.split() 函数

标签 c# linq-to-entities

<分区>

检查以下代码:

public IEnumerable<Query> GetAllQueries_FilteredOnCurrentUsersInvolvement(User user)
{
    var queries = _genericUnitOfWork.GenericRepository<Query>().Get(q =>
        q.AuthorUserID == user.ID ||
        q.ConsultantUserID == user.ID ||
        q.CreatorUserID == user.ID ||
        q.EngagementPartnerUserID == user.ID ||
        q.EQCRPUserID == user.ID ||
        q.LeadPartnerUserID == user.ID ||
        q.RMPUserID == user.ID ||
        (!string.IsNullOrEmpty(q.OthersInvolvedUserIDs) && q.OthersInvolvedUserIDs.Split(',').Contains(user.ID.ToString())),
        includeProperties: "NatureOfQuery");
    return queries;
}

它编译得很好。但是当你运行代码时:

{"LINQ to Entities does not recognize the method 'System.String[] Split(Char[])' method, and this method cannot be translated into a store expression."}

我可以自己编写 T-SQL 代码。如何让 LINQ to Entities 理解如何处理这个?

P.S> 会 this nuget package能解决这个问题吗?

建议的重复链接未提供任何解决此问题的答案。所以不,那没有回答这个问题。

最佳答案

拆分操作与查询一起发送,因此需要转换为 SQL 函数。这没有实现,因此不起作用。您需要检索数据并在内存中执行拆分。

关于c# - Linq to entities 无法处理 string.split() 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42435817/

相关文章:

c# - 在 FormView 中插入后获取返回值

c# - 从 MSTest 测试生成可运行的 exe

linq - 是否可以在没有LINQ的情况下使用 Entity Framework ?

linq - 无法创建类型 (type) 的常量值 在此上下文中仅支持原始类型 ('such as Int32, String, and Guid' )

entity-framework - 仅返回子实体 Linq Entity Framework

c# - 使用 Typeof 进行循环转换

c# - 从字符串(日期和时间)设置日期时间选择器

c# - Entity Framework 异常: Schema specified is not valid.

c# - Linq 到实体 : adding a where condition to a child relationship

c# - 使用 LINQ 从 ID 引用的表中获取记录名称