Support for stored procedures and custom SQL using LINQ to SQL

Source: Internet
Author: User
Tags sql using
This is a bit of scattered knowledge about LINQ to SQL. If you want to systematically learn about the knowledge of LINQ to SQL, please refer to scottgu's blog
  • Part 1: Introduction to LINQ to SQL
  • Part 2: defining our data model classes
  • Part 3: querying our database
  • Part 4: updating our database
  • Part 5: Binding UI using the ASP: linqdatasource Control
  • Part 6: retrieving data using Stored Procedures
  • Part 7: updating our database using Stored Procedures
  • ......
    the default curd behavior of LINQ to SQL is a LINQ expression, such as obtaining data.
    northwinddatacontext northwind = new northwinddatacontext ();
    var Product = from P in northwind. products
    where p. categoryid = 1
    select P;
    the LINQ expression dynamically generates an SQL statement at runtime.
    LINQ to SQL also supports stored procedures and custom SQL.
    1. sp
    drag a written stored procedure to the right of the design panel, in this way, we can use the northwinddatacontext instance to call the stored procedure and convert it into an instance method. This is too simple.
    the returned value of a stored procedure is a new data type automatically generated. The naming rule is stored procedure name + result, when you drag SP to the left of the designer to specify the data type, the return value of the method generated by SP is a set of this type. The returned result set also supports the modification and deletion operations of LINQ to SQL.
    SP support for insert, update, and delete operations
    2. Custom SQL
    the built-in executequery of northwinddatacontext provides support for custom SQL queries, you can write and query SQL statements like above, or return custom objects.
    the returned result set is also applicable to the modification and deletion operations on objects by using LINQ to SQL.
    for the modified and deleted custom SQL statements, execute with executecommand

    objects are updated, deleted, and rule verification are also supported, regardless of the LINQ to SQL expression, SP, or custom SQL.

    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.