How can I return a list that contains the result of a LINQ to SQLquery? I'm trying this implementation, but I got this error.
Cannot implicitly convert type
'System.Collections.Generic.List<AnonymousType#1>'
to'System.Collections.Generic.List<object>
Any help would be appreciated.
public List<Object> getShoes()
{
var query = from b in db.BrandTbls.AsQueryable()
join m in db.ShoeModelTbls on b.BrandID equals m.BrandID
join s in db.ShoeTbls on m.ModelID equals s.ModelID
join i in db.ShoeImageTbls on s.ShoeID equals i.ShoeID
select new { s.ShoeID, s.Size, s.PrimaryColor, s.SecondaryColor, s.Quantity, m.ModelName, m.Price, b.BrandName, i.ImagePath };
return query.ToList();
}
C programming does not allow to return an entire array as an argument to a function. However, you can return a pointer to an array by specifying the array's name without an index.
In C or C++, we cannot return multiple values from a function directly. In this section, we will see how to use some trick to return more than one value from a function. We can return more than one values from a function by using the method called “call by address”, or “call by reference”.
Although functions cannot return arrays, arrays can be wrapped in structs and the function can return the struct thereby carrying the array with it.
Anonymous types are specifically designed to be used entirely within the scope in which they are defined. If you want to return the results of the query out from this method, you should create a new named type to represent the results of your query and select instances of that named type, not instances of an anonymous type.
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