General Code for database operations based on. Net-based LINQ to SQL three-tier architecture development

Source: Internet
Author: User

Continued. Net-based LINQ
The three-tier architecture of SQL is developed. The following describes the common code used by each layer to query, insert, delete, and update databases.

Dal Layer Code

// Dalmanager. CS

Using system. Data. LINQ;
Using datalinq;

Namespace dal
{
Public class dalmanager
{
Private datalinq. dblinqdatacontext objdatacontext = new datalinq. dblinqdatacontext ();

Public dalmanager ()
{
}

Public table <m_manager> selectrecordall ()
{
Try
{
Return objdatacontext. m_manager;
}
Catch (exception ex)
{
Throw ex;
}
}

Public m_manager selectrecordbyid (string managerid)
{
Try
{
Return (from MNG in objdatacontext. m_manager
Where MNG. managerid = managerid
Select MNG). Single ();
}
Catch
{
Return NULL;
}
}


Public String insertrecord (m_manager localtable)
{
Try
{
Objdatacontext. m_manager.insertonsubmit (localtable );
Objdatacontext. submitchanges ();

Return localtable. managerid;
}
Catch (exception ex)
{
Throw ex;
}
}

Public void UpdateRecord (m_manager localtable)
{
Try
{
Objdatacontext. m_manager.attach (localtable );
Objdatacontext. Refresh (refreshmode. keepcurrentvalues, localtable );
Objdatacontext. submitchanges (conflictmode. continueonconflict );
}
Catch (exception ex)
{
Throw ex;
}
}

Public void deleterecord (string managerid)
{
Try
{
Objdatacontext. m_manager.deleteonsubmit (from MNG in objdatacontext. m_manager
Where MNG. managerid = managerid
Select MNG). Single ());
}
Catch (exception ex)
{
Throw ex;
}
}
}
}

Bll Layer Code

// Bllmanager. CS

Using system. Data. LINQ;
Using Dal;
Using datalinq;

Namespace BLL
{
Public class bllmanager
{
Public bllmanager ()
{
}

Private Dal. dalmanager objdataaccess = New DAL. dalmanager ();

Public table <m_manager> selectrecordall ()
{
Return objdataaccess. selectrecordall ();
}

Public m_manager selectrecordbyid (string managerid)
{
Return objdataaccess. selectrecordbyid (managerid );
}

Public String insertrecord (m_manager localtable)
{
Return objdataaccess. insertrecord (localtable );
}

Public void UpdateRecord (m_manager localtable)
{
Objdataaccess. UpdateRecord (localtable );
}

Public void deleterecord (string managerid)
{
Objdataaccess. deleterecord (managerid );
}
}
}

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.