Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot implicitly convert type 'System.Linq.IQueryable to System.Data.Entity.DbSet

Tags:

linq

I get the following error:

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

I have the following code:

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.

like image 288
Nate Pet Avatar asked Aug 25 '26 04:08

Nate Pet


1 Answers

I think you need

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

    }
like image 140
Sidharth Mudgal Avatar answered Aug 28 '26 07:08

Sidharth Mudgal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!