小编ela*_*ani的帖子

将IList <int>强制转换为IList <string>

我的EFService中的代码:

    private IDbSet<Item> _Items;
    private int _SearchTakeCount = 10;
    public IList<string> SearchByArticleCount(int articleCount)
        {
            return _Items.AsNoTracking().Where(m => m.Articles.Count().Equals(articleCount))
                .Take(_SearchTakeCount)
                .Select(m => m.Articles.Count().ToString())
                .Distinct()
                .ToList();
        }
Run Code Online (Sandbox Code Playgroud)

我的控制器中的代码:

public virtual ActionResult AutoCompleteSearch(string term, KeywordSearchBy searchBy = KeywordSearchBy.Name)
        {
            IList<string> data = new List<string>();
        switch (searchBy)
        {
            case ItemSearchBy.Name:
                data = _ItemService.SearchByName(term);
                break;
            case ItemSearchBy.ArticleCount:
                int articleCount = Convert.ToInt32(term);
                data = _ItemService.SearchByArticleCount(articleCount);
                break;
        }
Run Code Online (Sandbox Code Playgroud)

当我运行项目时,异常是有效的.这个例外是:LINQ to Entities无法识别方法'System.String ToString()'方法,并且此方法无法转换为存储表达式.

c# asp.net-mvc casting controller converter

0
推荐指数
1
解决办法
544
查看次数

标签 统计

asp.net-mvc ×1

c# ×1

casting ×1

controller ×1

converter ×1