haa*_*nsi 0 .net c# linq entity-framework c#-4.0
我正在使用EF通用存储库并具有此功能.
public IEnumerable<T> Query(Expression<Func<T, bool>> filter)
{
return objectSet.Where(filter);
}
Run Code Online (Sandbox Code Playgroud)
它工作正常,在我在这样的类中使用此函数之前:
private void BindProbabationPeriod()
{
ddlProbabationPeriod.DataSource = context.PeriodRepository.Query(a => a.EntityId == selectedEntityId);
ddlProbabationPeriod.ValueMember = "Id";
ddlProbabationPeriod.DisplayMember = "ProbabationPeriod";
}
Run Code Online (Sandbox Code Playgroud)
因为我刚刚开始使用LINQ,所以我没有好好处理它.你能指导我如何添加和(和条件)在这种情况下.我想修改它并添加另一个条件,名称列不应为空.
请注意,此实例为Period,因此存储库为PeriodRepository.
context.PeriodRepository.Query(a => a.EntityId == selectedEntityId and a.Name!=null);
Run Code Online (Sandbox Code Playgroud)
这应该工作:
context.PeriodRepository.Query(a => a.EntityId == selectedEntityId && a.Name != null);
Run Code Online (Sandbox Code Playgroud)