Entity SQL usage in EF

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.