I am trying to pull some records from a table (BidNames) and pass them to a view in a view model. My view model consists of nothing more than a collection of BidName records.
My view model:
public class BidNamesVM
{
public IEnumerable<BidName> BidNames { get; set; }
}
I’m having problems populating the BidNames collection. The conversion from bn to BidNames isn’t working.
from bn in BidNames
where bn.CustomerID == 1160 && bn.Customer.Bids.Any(b=>b.Item.AuctionID == 2)
select new BidNamesVM
{
BidNames = bn
}
What do I have to do to populate BidNames in my query?
Many thanks,
BK
Your LINQ query already returns an
IEnumerable<BidName>, withbnrepresenting an individual instance ofBidName. Try this:In your example, you were trying to set an instance of
BidNameto a property of typeIEnumerable<BidName>, which won’t work for obvious reasons.