2014年10月24日 星期五

Use Func as filters of LINQ


For example
/// Get
public IQueryable<ChtAlarmEvent> GetList(Func<ChtAlarmEvent, bool> filter)
{
var entities = this._dbContext.ChtAlarmEvents.Where(filter).AsQueryable();
return entities;
}

Unit Test
[TestMethod]
public void TestGetList()
{
using (var da = new ChtAlarmEventDAL(chtContext))
{
var entities = da.GetList(x => x.Severity == Severity.Critical.ToString());
foreach (var data in entities){
Debug.WriteLine("UUID : " + data.UUID);
}
entities = null;
    }
}



沒有留言:

張貼留言