This is in ASP.NET MVC 4,
I have a Portfolios Table and one of the properties of the Portfolio class is an ICollection of Stocks. Stocks have a string property: Symbol. If I have the portfolio object I am trying to check the symbol of a specific stock to see if it matches what I am looking for.
private PortfolioDb _db = new PortfolioDb();
public ActionResult Index([Bind(Prefix="id")]int portfolioId,
string searchTerm = null)
{
var portfolio = _db.Portoflios
.Where(p=> searchTerm == null ||
(p.Id == portfolioId && p.Stocks.Symbol == searchTerm)
So p.Stocks
is my ICollection
of Stocks and I want to check the symbol of all those stocks to see if they match the searchTerm. However, I cannot do p.Stocks.Symbol
and I am wondering how I would access each symbol of each item in the Stocks collection.
Thanks