Use .Concat()
I am not absolutely sure if I understood you question correctly, but this code will create a resultset that is appended to if your if conditions are true, rather than replacing the original resultset.
var results=(from a in alist where a.id==id select a)
if(...something)
{
results = results.Concat((from a in alist where a.amount>input1 && a.typeId==1 select a))
}
if(...something else)
{
results = results.Concat((from a in alist where a.amount>input2 && a.typeId==2 select a))
}
//....
Edited as per Peter B's comment.
If multiple lists may contain the same element and you only wish to have every element at most once, use .Union
instead of .Concat
. This has some performance penalty of course (having to compare the elements).
After your edit
Your edit clarified things a bit. You have two options:
Move your a.id == id
check into the inner queries:
var results=Enumerable.Empty<typeofa>()
if(...something)
{
results = results.Concat((from a in alist where a.id == id && a.amount>input1 && a.typeId==1 select a))
}
if(...something else)
{
results = results.Concat((from a in alist where a.id == id && a.amount>input2 && a.typeId==2 select a))
}
//....
First filter the set using the id, materialize that, then further narrow that down using the method I showed above.
var results=Enumerable.Empty<typeofa>();
var fileterdList = (from a in alist where a.id==id select a).ToList();
if(...something)
{
results = results.Concat((from a in fileterdList where a.amount>input1 && a.typeId==1 select a))
}
if(...something else)
{
results = results.Concat((from a in fileterdList where a.amount>input2 && a.typeId==2 select a))
}
//....
Whichever works better depends on your situation. General advice is that prefiltering is more efficient if it narrows down the list considerably and/or the original source is relatively expensive to query (sql for example), but as always, you should profile your concrete example yourself.