I need to know about using PredicateBuilder
. On almost every example of how to use it, they show the code as follows:
var predicate = PredicateBuilder.True<employee>();
if (!string.IsNullOrEmpty(txtAddress.Text))
predicate = predicate.And(e1 => e1.Address.Contains(txtAddress.Text));
if (!string.IsNullOrEmpty(txtEmpId.Text))
predicate = predicate.And(e1 => e1.Id == Convert.ToInt32(txtEmpId.Text));
if (!string.IsNullOrEmpty(txtDesc.Text))
predicate = predicate.And(e1 => e1.Desc.Contains(txtDesc.Text));
if (!string.IsNullOrEmpty(txtName.Text))
predicate = predicate.And(e1 => e1.Name.Contains(txtName.Text));
EmployeeDataContext edb= new EmployeeDataContext();
var emp = edb.Employees.Where(predicate);
grdEmployee.DataSource = emp.ToList();
grdEmployee.DataBind();
What is that Employee
object, the one between the greater than and less than brackets? I have racked my brains on that one. I am using Linq to SQL entities and I get compile errors when I try this myself. I think the errors are something like:
"Cannot cast from a Linq table to..."
I am a beginner. Please forgive me for asking what may be an obvious thing. Thank you.
<...>
are called generics, i don't know how to use linq but maby this helps: msdn.microsoft.com/en-us/library/bb546142.aspx – Antilogy