InvalidOperationException:输入从作用域''引用的'System.String',但它未定义

时间:2016-11-21 19:54:42

标签: c# linq asp.net-core asp.net-core-mvc entity-framework-core

我已升级到Core 1.1和Visual Studio 2017.我正在运行一个简单的现有代码行来搜索用户输入字符串的列,但会收到错误...

  

InvalidOperationException:类型的变量'__searchTerm_1'   'scope.String'从范围''引用,但未定义

简而言之,我的守则是:

public IQueryable<SearchViewModel> ActivitySearch(string searchTerm)
{
    var qry = (from act in context.Acts
                  .Include(x => x.ActivityExt)
               select new SearchViewModel()
               {
                   AMCNnumber = act.AMCNnumber
                   ActivityId = act.ActivityID,
                   ImplementingPartner = act.ActivityExt.imp,
                   ProjectTitle = act.Name,
                   Description = act.Description,
                   StartDate = act.StartDate,
                   EndDate = act.EndDate
               });

     if (!String.IsNullOrEmpty(searchTerm))
     {
         qry = qry.Where(x => x.AMCNnumber.Contains(searchTerm);
     } 

     return qry.ToArray();
}

1 个答案:

答案 0 :(得分:0)

事实证明,我遇到的子查询导致错误。我必须创建单独的变量来获取ID。