public IEnumerable<Products_Products> getprod()
{
var db = new Model.atengturonDBEntities();
IEnumerable<Products_Products> x = new List<Products_Products>();
var test = (from name in db.Products_Products select
name.ProductName).ToList();
x = test;
return x;
}
why am I getting this error? I also tried to change all 'IEnumerable' to 'List', Help me! thanks :)
Cannot implicitly convert type 'System.Collections.Generic.List' to 'System.Collections.Generic.IEnumerable'. An explicit conversion exist(are you missing a cast?)
Error message is quite clear. Your LINQ query returns collection of string
, because you're selecting name.ProductName
, but your method is declared to return collection of Products_Products
.
Change your LINQ query to return not just ProductName
but the product itself:
IEnumerable<Products_Products> x = new List<Products_Products>();
var test = (from name in db.Products_Products select
name).ToList();
(can also be replaced with just db.Products_Products.ToList()
.
Or change your method to return IEnumerable<string>
public IEnumerable<string> getprod()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With