Comparison operators not supported for type 'System.String[]'

后端 未结 5 2123
渐次进展
渐次进展 2020-12-11 22:20

why this line:

var category = _dataContext.Categories.Where(p => p.Keywords.Split(\' \').Contains(context.Request.QueryStrin         


        
5条回答
  •  爱一瞬间的悲伤
    2020-12-11 22:55

    string.split is not supported in LINQ-to-SQL.

    There's an easy fix. Select all the data and do the filtering in the client. This may not be very efficient depending on the number of categories.

    var category = 
        _dataContext.Categories.ToList()
        .Where(p => p.Keywords.Split(' ').Contains(context.Request.QueryString["q"])).First();
    

    Calling .ToList() will force enumeration of all the categories from your datasource, and the subsequent operations will be performed in the client code.

提交回复
热议问题