Predicate builder using linq
I have a 6 text boxes. I want to search and retrive from database what we have entered in textboxes. I am using
4-Tier Architecture. i have business object and DataAccesLayer, dbml, presentation layer.
I am using linq to sql in this architecture. I want to use predicate builder in this search method.
can u please tell me how to use . i have given like this.
BO.
namespace BusinessObject
{
public class companies:Icompanies
{
int _empid = 0;
public int empid
{
set
{
_empid = value;
}
get
{
return _empid;
}
}
string _empname = null;
public string empname
{
get
{
return _empname;
}
set
{
_empname = value;
}
}
int _jobid = 0;
public int jobid
{
get
{
return _jobid;
}
set
{
_jobid = value;
}
}
DateTime _hiredate;
public DateTime? hiredate
{
get
{
return _hiredate;
}
set
{
_hiredate = value.HasValue ? value.Value : new DateTime();
}
}
int _salary = 0;
public int? salary
{
get
{
return _salary;
}
set
{
_salary = value.HasValue ? value.Value : new Int32();
}
}
int _departmentid = 0;
public int? departmentid
{
get
{
return _departmentid;
}
set
{
_departmentid = value.HasValue?value.Value:new Int32();
}
}
}
}
In DAL i have given predicate builder.cs
namespace DataAccessLayer
{
public static class PredicateBuilder
{
public static Expression<Func<T, bool>> True<T>() { return f => true; }
public static Expression<Func<T, bool>> False<T>() { return f => false; }
public static Expression<Func<T, bool>> Or<T>(this Expression<Func<T, bool>> expr1,
Expression<Func<T, bool>> expr2)
{
var invokedExpr = Expression.Invoke(expr2, expr1.Parameters.Cast<Expression>());
return Expression.Lambda<Func<T, bool>>
(Expression.Or(expr1.Body, invokedExpr), expr1.Parameters);
}
public static Expression<Func<T, bool>> And<T>(this Expression<Func<T, bool>> expr1,
Expression<Func<T, bool>> expr2)
{
var invokedExpr = Expression.Invoke(expr2, expr1.Parameters.Cast<Expression>());
return Expression.Lambda<Func<T, bool>>
(Expression.And(expr1.Body, invokedExpr), expr1.Parameters);
}
}
}
in Presentation Layer i have given 4 textboxes
<table>
<tr>
<td>
<asp:Label ID="lblempid" runat="server" Text="EmployeeID"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtempid" runat="server"></asp:TextBox>
</td>
<td>
</td>
<td>
<asp:Label ID="lblempname" runat="server" Text="EmployeeName"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtempname" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblhiredate" runat="server" Text="Hiredate"></asp:Label>
</td>
<td>
<asp:TextBox ID="txthiredate" runat="server" ></asp:TextBox>
<asp:CalendarExtender ID="txthiredate_CalendarExtender" runat="server"
Enabled="True" TargetControlID="txthiredate">
</asp:CalendarExtender>
</td>
<td>
 
</td>
<td>
<asp:Label ID="lbldepartmentid" runat="server" Text="DepartmentId"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtdepartmentid" runat="server"></asp:TextBox>
</td>
</tr>
<tr align="center">
<td>
<asp:Button ID="btnsearch" runat="server" Text="Search"
onclick="btnsearch_Click" />
</td>
</tr>
</table>
in aspx.cs
protected void btnsearch_Click(object sender, EventArgs e)
{
companies cmp = new companies();
employ emp = new employ();
cmp.empid = Convert.ToInt32(txtempid.Text);
cmp.empname = txtempname.Text;
cmp.hiredate = Convert.ToDateTime(txthiredate.Text);
cmp.departmentid = Convert.ToInt32(txtdepartmentid.Text);
emp.searchemployes(cmp);
}
IN DAL
public List<companies> searchemployee(companies cmp)
{
List<companies> list = new List<companies>();
var predicate = PredicateBuilder.True<companies>();
Employee emp = new Employee();
?
}
from here i am not getting
please help