Поскольку select new { s.width, s.height, s.number}
означает System.Linq.IQueryable<AnonymousType#1>
, но ваша функция ожидает возврата IQueryable<Product>
. Измените свой код на:
public IQueryable<Product> ListProducts(string prodcutType)
{
var results = from p in db.Products
join s in db.Stocks
on p.ID equals s.IDProduct
where p.ptype == prodcutType
select p;
return results;
}
ОБНОВЛЕНИЕ:
Или, может быть, вы хотите IQueryable<Stock>
:
public IQueryable<Stock> ListProducts(string prodcutType)
{
var results = from p in db.Products
join s in db.Stocks
on p.ID equals s.IDProduct
where p.ptype == prodcutType
select s;
return results;
}
Если вы хотите только 3 свойства: ширина + высота + число, создайте новый тип. Например:
public class SomeType {
public int Width { get; set; }
public int Height { get; set; }
public int Number { get; set; }
}
public IQueryable<SomeType> ListProducts(string prodcutType)
{
var results = from p in db.Products
join s in db.Stocks
on p.ID equals s.IDProduct
where p.ptype == prodcutType
select new SomeType {
Width = s.width,
Height = s.height,
Number = s.number
};
return results;
}