how to add multiple conditions in this lambda function?

.net c# c#-4.0 entity-framework linq

Question

I am working with EF generic repository and have this function.

public IEnumerable<T> Query(Expression<Func<T, bool>> filter)
    {
        return objectSet.Where(filter);
    }

It is working fine and before I have used this function in a class like this:

 private void BindProbabationPeriod()
    {
        ddlProbabationPeriod.DataSource = context.PeriodRepository.Query(a => a.EntityId == selectedEntityId);
        ddlProbabationPeriod.ValueMember = "Id";
        ddlProbabationPeriod.DisplayMember = "ProbabationPeriod";
    }

Because I just have started using LINQ I don't have a good hand on it. Can you please guide me how I should add and (& with condition) in this condition. I want to modify it and add another condition that Name columns should not be empty.

Please note this instance is Period so repository is PeriodRepository.

context.PeriodRepository.Query(a => a.EntityId == selectedEntityId and a.Name!=null);
1
0
12/27/2013 2:09:59 PM

Accepted Answer

This should work:

context.PeriodRepository.Query(a => a.EntityId == selectedEntityId && a.Name != null);
7
8/10/2012 12:39:22 AM

Popular Answer

this will also work

context.PeriodRepository.Query(a => a.EntityId == selectedEntityId).Where(a =>  a.Name != null);


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow