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 );
}
}
}