Question

I am beginner in repository design pattern.So i want to learn how to use "where" in repository.

I have repository code below,

Model

public T First(Expression<Func<T, bool>> where)
{
return DbSet.First(where);
}

I want to use where clause below however , i do not know what parameter i must give in order to "where" clause ?

Controller:

var r = new Repository<Department>(new MyDbEntities());

r.First(..........) // it says (Expression<FuncDepartment,bool>>where):Department

I want to match department name in my database departmane name field.

What to add in stead of "........." ?

Was it helpful?

Solution

Just pass Func<Department, bool> - it will be converted to expression:

r.First(d => d.Name == "department name")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top