Public list<policecase> getpolicecaselist (policecasefilter view)
{
String sqlString = "Select Value pc from entities.policecase as PC";
var where = "";
if (!string. Isnullorwhitespace (view. caseaddress))
{
Police address
if (where! = "")
{
where + = "and PC. [Police address] like '% ' + view. caseaddress + "% '";
}
Else
{
where + = "where pc." [Police address] like '% ' + view. caseaddress + "% '";
}
}
if (!string. Isnullorwhitespace (view. Casetype))
{
Type of police sentiment
if (where! = "")
{
where + = "and PC. [Type of police sentiment] like '% ' + view. Casetype + "% '";
}
Else
{
where + = "where pc." [Type of police sentiment] like '% ' + view. Casetype + "% '";
}
}
if (!string. Isnullorwhitespace (view. StartTime))
{
Alarm Time
if (where! = "")
{
where + = "and PC. [Alarm time] >=datetime ' + convert.todatetime (view. StartTime). ToString ("Yyyy-mm-dd HH:mm:ss") + "'";
}
Else
{
where + = "where pc." [Alarm time] >=datetime ' + convert.todatetime (view. StartTime). ToString ("Yyyy-mm-dd HH:mm:ss") + "'";
}
}
if (!string. Isnullorwhitespace (view. EndTime))
{
Alarm Time
if (where! = "")
{
where + = "and PC. [Alarm time] <=datetime ' + convert.todatetime (view. EndTime). ToString ("Yyyy-mm-dd HH:mm:ss") + "'";
}
Else
{
where + = "where pc." [Alarm time] <=datetime ' + convert.todatetime (view. EndTime). ToString ("Yyyy-mm-dd HH:mm:ss") + "'";
}
}
if (!string. Isnullorwhitespace (view. Policestation))
{
Affiliated Branch
if (where! = "")
{
where + = "and PC. [Affiliated branch] like '% ' + view. Policestation + "% '";
}
Else
{
where + = "where pc." [Affiliated branch] like '% ' + view. Policestation + "% '";
}
}
if (!string. Isnullorwhitespace (view. Rpttype))
{
Alarm Type
if (where! = "")
{
where + = "and PC. [Alarm type] like '% ' + view. Rpttype + "% '";
}
Else
{
where + = "where pc." [Alarm type] like '% ' + view. Rpttype + "% '";
}
}
SqlString + = where;
var objctx = (Repository as Iobjectcontextadapter). ObjectContext;
objectquery<policecase> pc = Objctx. Createquery<policecase> (sqlString);
var data = pc. ToList ();
return data;
}
}
Entity SQL usage in EF