A followup to this previous question:
Current code:
var query = from b in books
select new
{
Title = b.Title,
StockAvailable = bookexamples.Count(be =>
be.BookID == b.BookID &&
be.OrderDetailID == null
)
};
Goal:
Replace query with an IEnumerable<test> that should contain strongly-typed data from the LINQ query.
public class test
{
public string Title { get; set; }
public List<int> StockAvailable { get; set; }
}
Problem:
Recieve a error message:
Error 1 Cannot implicitly convert type
'System.Collections.Generic.IEnumerable<AnonymousType#1>'
to
'System.Collections.Generic.IEnumerable<BokButik1.Models.test>'.
An explicit conversion exists (are you
missing a cast?)
Question:
How should I solve this problem?
// Fullmetalboy
You need to modify the query to return
testobjects (currently, it is returning anomynous objects).You’ll need to adjust
StockAvailableto represent anintasCountreturns an int.Also, note, that class names in C# are written with a capital letter at the beginning.