haansi
haansi

Reputation: 5730

EF repository Query method, how to mention other entity in expression?

In EF generic repoistory my Query method is as below:

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

I have used this method to filter data like:

Repository.Query(a=>a.EntityId==selectedId);

Below is my tables structure.

  1. Entity (Id, Name)
  2. Title (Id,Name,EntityId)
  3. Level (Id, Name,TitleId)

I know EntityId and based I want to filter data from Level table but Entity and Levle table are not connected directly, Level is attaching them.

Please guide how I should write write lambda expression to pass to Query method.

Thanks

Edit ObjectSet type is Level.

Upvotes: 0

Views: 238

Answers (1)

Mark Oreta
Mark Oreta

Reputation: 10416

Assuming that you're using standard names for your navigation properties you should be able to do this:

Repository.Query(level => level.Title.Entity.EntityId == selectedId);

If not, can you post your model?

Upvotes: 1

Related Questions