3

我收到以下错误:

无法将类型“System.Linq.IQueryable”隐式转换为“System.Data.Entity.DbSet”。
存在显式转换(您是否缺少演员表?)

我有以下代码:

var reports = dbContext.Product;

if (searchField == "StoreNum")
{
    int storeNum;
    int? stnum = int.TryParse(searchString, out storeNum) ? storeNum : (int?)null;

    reports = dbContext.Product
        .Where(w => w.StoreNum == stnum); // error occurs here when I try to build
}

我不明白为什么我会收到此消息。

4

2 回答 2

1

我想你需要

List<ProdVal> reports;

if (searchField == "StoreNum")
    {
        int storeNum;
        int? stnum = int.TryParse(searchString, out storeNum) ? storeNum : (int?)null;

       reports = (dbContext.Product
                 .Where(w => w.StoreNum == stnum)).ToList(); // error occurs here when I try to build

    }
于 2012-10-08T19:52:36.083 回答
0
 var reports = dbContext.Product.ToList();

        if (searchField == "StoreNum")
        {
            int storeNum;
            int? stnum = int.TryParse(searchString, out storeNum) ? storeNum : (int?)null;

           reports = reports
          .Where(w => w.StoreNum == stnum).AsQueryable(); // error occurs here when I try to build

        }
于 2012-10-09T07:06:11.887 回答