Entity Framework Code First executes SQL statements, views, and stored procedures

Source: Internet
Author: User

1. Entity Framework Code First query table or view

 var  provincelist = ctx. Provinces.sqlquery ( " select TOP * from province      "  foreach  (var  province in   Provincelist) {Console.WriteLine ( "  {0}-{1}-{2}   " 
    var provincelist = ctx. Database.sqlquery<tempprovince> ("select TOP Ten provinceno,provincename from province" );     foreach (var in provincelist)    {        Console.WriteLine ("{0}-{1}", province. Provinceno, Province. provincename);    }

3. Entity Framework Code First executes stored procedure

 create PROCEDURE Getcitybyprovinceid (@ProvinceID INT) as SELECT  * from the city WHERE provinceid  = @ProvinceID 
using (varnew  Portalcontext ()) {    var citylist = ctx. Cities.sqlquery ("dbo. Getcitybyprovinceid @p0"3);     foreach (var in citylist)    {        Console.WriteLine ("{0}-{1}-{2}-{3}", City. Cityid, City. Provinceid, City. Cityno, City. CityName);}    }

Stored procedure Multiple input parameters:

var " Australia " ; var " Beach, Sun " ; var destinations = context. Database.sqlquery<destinationsummary> ("dbo. Getdestinationsummary @p0, @p1", Country, keyWords);

Entity Framework Code First executes SQL statements, views, and stored procedures

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.