Related Operations for WEBFORM--LINQ

Source: Internet
Author: User

Linq:lineq to SQ class: Integrated data access class; no difference from ADO;
--------------------------------------------
Creation of LINQ:
Right-click, add New Item, LinQ to SLQ class, suffix name dbml;
A database corresponds to a database;

LINQ operation:
Query all:
//instantiation
Data0617datacontext con = new Data0617datacontext ();
Public List<uesr>select ()
{
return con. Users.tolist ();
}
--------------------
Conditional query:
(exact lookup) Click Query:
//LAMDBA expression (traverse all data)
Public List<uesr>select ( String name)
{
return con. Users.where (R=>r.username==name). ToList ();
}
--------
Field extension: (for example, national display)
"recreate a partial class"
Public partial class Users
{
//have a primary foreign key relationship,
Public String Nname{get{return Nation1.nationname}}
}
------------------------------------------
Additions and deletions of LINQ:
Increase (ADD):
public void Insert (Users)
{
Con. Users.insertonsubmit (U);
Con. SubmitChanges ();
}
Delete:
public void Delete (string Uname)
{
Users uu=con. Users.where (R=>r.username==uname). FirstOrDefault ()
if (uu!=null)
{
Con. Users.deleteonsubmit (UU);
Con. SubmitChanges ();
}
}
Modify:

public void Update (Users u)
{
Users Uuu=con. Users.where (R=>r.username==u.username). FirstOrDefault ()
UuU. Passward=u.passward;
Con. SubmitChanges ();
}

Related Operations for WEBFORM--LINQ

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.