Create linq and provide filter inline

Monday, July 7, 2014

Im using the following linq code and I want to know if there is a way that instead of the filter that I doing after the link to result I can put this inside the linq to save time ...is it possible?



IEnumerable<TableEntry> Result = null;

TableServiceContext context = GetTableServiceContext();

Result = from ObjList in context.CreateResult<TableEntry>(TableConstants.Table_TABLE_NAME).AsTableServiceResult<TableEntry>(context).Execute()
where ObjList.Timestamp <= toDateTime
&& ObjList.Timestamp >= fromDateTime
orderby ObjList.Timestamp descending
select ObjList;


Here I start to do filter which I want to do insinde the linq itself if possible...



if (dataName != null)
{
Result = Result.Where(ObjList => ObjList.Provider.Equals(dataName));
}
if (TableLevel != null)
{
int level = (int)TableLevel;
Result = Result.Where(ObjList => ObjList.Tablelevel == level);
}
if (TableType != null)
{
int type = (int)TableType;
Result = Result.Where(ObjList => ObjList.Type == type);
}






http://ift.tt/1rG76ZU