无法将类型'System.Linq.IQueryable隐式转换为System.Data.Entity.DbSet [英] Cannot implicitly convert type 'System.Linq.IQueryable to System.Data.Entity.DbSet

查看:365
本文介绍了无法将类型'System.Linq.IQueryable隐式转换为System.Data.Entity.DbSet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到以下错误:

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

Cannot implicitly convert type 'System.Linq.IQueryable' to 'System.Data.Entity.DbSet'.
An explicit conversion exists (are you missing a cast?)

我有以下代码:

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
}

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

I cannot understand why I am getting this message.

推荐答案

 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

        }

这篇关于无法将类型'System.Linq.IQueryable隐式转换为System.Data.Entity.DbSet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆