Please see code below:
using (var context = new MusicCatelogContext())
{
try
{
albumList = context.Albums
.Where(a => a.ReleaseYear.Equals(year))
.Where(a => a.Composer.Equals(composer))
.ToList<AlbumEntity>();
}
catch (Exception e)
{
Trace.WriteLine(e.Message);
Trace.WriteLine(e.InnerException);
}
}
I am trying to add those Where methods conditionally, so something like:
albumList = context.Albums
if (someCondition)
{
.Where(a => a.ReleaseYear.Equals(year));
}
if (someOtherCondition)
{
.Where(a => a.Composer.Equals(composer));
}
.ToList<AlbumEntity>();
However, I get a "Where does not exist in the current context" compiler error.
How can I achieve this? Thanks.