I have a :
var query = db.vw_web_GetAccounts; //a sql view
if (some condition)
{
query.Where(...);
}
else
{
query.Where(...);
}
query.Select(a => new AccountVM
{
Name = a.Name,
....
});
return query.ToList();
I want to return List<AccountVM>
There is an compilation error:
Error CS0029 Cannot implicitly convert type 'System.Data.Entity.DbSet<vw_web_GetAccounts>' to 'System.Collections.Generic.List<AccountVM>'
Without the if condition example: It works as expected
var query = db.vw_web_GetAccounts
.Where(...)
.Select(a => new AccountVM
{
Name = a.Name,
....
});
return query.ToList();
How do I make it work with if condition?