使用三层体系结构中的select StoreProcedure检索数据 [英] Retrieving data using select StoreProcedure in Three Tier Architecture

查看:85
本文介绍了使用三层体系结构中的select StoreProcedure检索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

。,。,


这是Srikanth Akon,



      我已经创建了在线图书馆管理系统。在该项目中我跟随  3层架构。,。  像


                1.Data访问层,


                2.middle层


                3.presentation(UI Layer),,.


   1的数据访问层:


        &NBSP ;       在这个图层我创建了.dbml  file(LINQ to SQL),然后将我的Tables和Store Procedure拖放到其中。


   2. 中间层:


            在这一层包含3个类图书馆(.dll) 等,的


          &NBSP ;        。1.Business实体对象


                &NBSP ;  。2.Business层


                    3.服务层。


     3.presentation(UI Layer),,.


        在这层我有 所有aspx文件。,(Web表单)。



这是我的插入函数通过3层使用LINQ to SQL


  1.用户表的业务实体对象(BEO):


命名空间MiddleTier.LMS.BEO

{

  公共类LIBUsersBEO

    {

       public int LIBUserId {get;组; }
       public string LIBUserName {get;组; }
       public string LIBPassword {get;组; }
       public DateTime LIBUserDOB {get;组; }
       public int LIBUserAge {get;组; }
       public string LIBUserSex {get;组; }
       public string LIBUserCompanyEmailId {get;组; }
       public string LIBContactAddress {get;组; }
       public string LIBContactNumber {get;组; }
       public string LIBUserCountry {get;组; }
       public string LIBSecurityQuestion {get;组; }
      公共字符串LIBSecurityAnswer {get;组; }
       public DateTime LIBUserCreatedDate {get;组; }
       public int LIBUserCreatedBy {get;组; }
       public DateTime LIBUserModifiedDate {get;组; }
       public int LIBUserModifiedBy {get;组; }


    }



2.Business Layer。


命名空间MiddleTier.LMS .BusinessLayer

{

   公共类LIBUsersBO

    {

       公共LIBUsersBEO LIBUsersBEO {get;组; }


       公共LIBUsersBO(LIBUsersBEO UsersBEO)

        {

            this.LIBUsersBEO = UsersBEO;

        }     
$


        public int InsertLIBUsersValues()

        {

            INT InsertLIBUsersValue = 0;                      &NBSP ;                        &NBSP ;        


           试试
            {

               使用(DataAccessLayer的 LIBProjectDataContext 康恩=新        //&的 LIBProjectDataContext是我的dbml文件
           DataAccessLayer的 LIBProjectDataContext (ConfigurationManager.ConnectionStrings ["构造"]的ConnectionString。))

                 {



                &NBSP ;                        &NBSP ;                        &NBSP ; 
// <强> SPInsertLIBUsers 是我的商店程序

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; InsertLIBUsersValue =康恩的 SPInsertLIBUsers (&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;




&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ; LIBUsersBEO.LIBUserName,

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP; LIBUsersBEO.LIBPassword,

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; LIBUsersBEO.LIBUserAge,

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; LIBUsersBEO.LIBUserSex,

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&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NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP; LIBUsersBEO.LIBUserModifiedDate,

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP; LIBUsersBEO.LIBUserModifiedBy





&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; );;
                }
            }
            catch(例外情况)

            {

                throw ex;

            }
            return InsertLIBUsersValue;



        }


3。服务层。


命名空间MiddleTier.LMS.ServiceLayer

{

  公共类LIBUsersService

    {

      公共LIBUsersBEO LIBUsersBEO {get;组; }


       公共LIBUsersService(LIBUsersBEO UsersBEO)

        {

            this.LIBUsersBEO = UsersBEO;

        }&NBSP;&NBSP;&NBSP;  
$


        public int InsertLIBUsersValues()

        {

           返回新的LIBUsersBO(LIBUsersBEO).InsertLIBUsersValues();

        }


UI图层(在"提交"按钮


  protected void btnSubmit_Click(object sender,EventArgs e)

        {
$


            LIBUsersBEO UserBEO =新的LIBUsersBEO()

            {



                LIBUserName = txtUserName.Text,

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; LIBPassword = txtPassword.Text,

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; LIBUserDOB = Convert.ToDateTime(txtDOB.Text).Date,

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ; LIBUserSex = ddlUserSex.SelectedValue,

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; LIBUserCompanyEmailId =(txtEmailAddress.Text),

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; LIBUserCountry = txtCountry.Text,

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; LIBSecurityQuestion = ddlSQuestion.SelectedValue,

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; LIBSecurityAnswer = txtSAnswer.Text

               

            }


            LIBUsersService UserService = new LIBUsersService(UserBEO);

            int InsertLIBUsersRValue = UserService.InsertUsersRValues();



我正在添加 参考;


业务层:数据访问层,BEO


服务层  : Business Laye r, BEO


演示层:服务层 BEO


此插入函数工作正常,。,。以3层方式,




现在我有需要,如何使用LINQ to SQL
中的选择存储过程检索数据,并且还遵循3层方式,



帮助我。,。,,。


如果您有任何示例代码,参考链接和学习资料,。,。,


谢谢,







       &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;



解决方案

你还没有说出你遇到了什么问题,所以我无法帮助你。


一个注意事项,但是:不要使用"try / catch(Exception ex){throw ex;}"。完全省略try / catch。你的代码按原样会弄乱堆栈跟踪,使其看起来像是在"throw ex;"中发生的异常。言。


Hi,.,.,

This is Srikanth Akon,

       I Have create online Library Management System.,.In that Project am following  3-Tier architecture.,.   like

                1.Data Access Layer,

                2.middle tier

                3.presentation (UI Layer),,.

   1.Data Access Layer:

                 In this Layer I created .dbml  file(LINQ to SQL ), And I drag and drop my Tables and Store Procedure in that.

   2.Middle tier:

            In this tier contains 3 Class Libraris(.dll)  like,

                   1.Business Entity Objects.

                   2.Business Layer.

                   3. Service Layer.

    3.presentation (UI Layer),,.:

         In this Layer I have  all aspx files.,(Web forms).

Here is my Insert function Through 3-tier using LINQ to SQL

 1.Business Entity Objects(BEO) for User Table:

namespace MiddleTier.LMS.BEO
{
   public class LIBUsersBEO
    {
       public int LIBUserId { get; set; }
       public string LIBUserName { get; set; }
       public string LIBPassword { get; set; }
       public DateTime LIBUserDOB { get; set; }
       public int LIBUserAge { get; set; }
       public string LIBUserSex { get; set; }
       public string LIBUserCompanyEmailId { get; set; }
       public string LIBContactAddress { get; set; }
       public string LIBContactNumber { get; set; }
       public string LIBUserCountry { get; set; }
       public string LIBSecurityQuestion { get; set; }
       public string LIBSecurityAnswer { get; set; }
       public DateTime LIBUserCreatedDate { get; set; }
       public int LIBUserCreatedBy { get; set; }
       public DateTime LIBUserModifiedDate { get; set; }
       public int LIBUserModifiedBy { get; set; }

    }

2.Business Layer.

namespace MiddleTier.LMS.BusinessLayer
{
    public class LIBUsersBO
    {
        public LIBUsersBEO LIBUsersBEO { get; set; }

        public LIBUsersBO(LIBUsersBEO UsersBEO)
        {
            this.LIBUsersBEO = UsersBEO;
        }     

        public int InsertLIBUsersValues()
        {
            int InsertLIBUsersValue = 0;                                                        
            try
            {
                using (DataAccessLayer.LIBProjectDataContext conn = new        // LIBProjectDataContext is my dbml file           DataAccessLayer.LIBProjectDataContext(ConfigurationManager.ConnectionStrings["conStr"].ConnectionString))
                {

                                                                     //SPInsertLIBUsers is my store procedure
                    InsertLIBUsersValue = conn.SPInsertLIBUsers(           

                        LIBUsersBEO.LIBUserName,
                        LIBUsersBEO.LIBPassword,
                        LIBUsersBEO.LIBUserAge,
                        LIBUsersBEO.LIBUserSex,
                        LIBUsersBEO.LIBUserCompanyEmailId,
                        LIBUsersBEO.LIBContactAddress,
                        LIBUsersBEO.LIBContactNumber,
                        LIBUsersBEO.LIBUserCountry,
                        
                        LIBUsersBEO.LIBUserCreatedDate,
                        LIBUsersBEO.LIBUserCreatedBy,
                        LIBUsersBEO.LIBUserModifiedDate,
                        LIBUsersBEO.LIBUserModifiedBy


                        );
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return InsertLIBUsersValue;

        }

3. Service Layer.

namespace MiddleTier.LMS.ServiceLayer
{
   public class LIBUsersService
    {
       public LIBUsersBEO LIBUsersBEO { get; set; }

        public LIBUsersService(LIBUsersBEO UsersBEO)
        {
            this.LIBUsersBEO = UsersBEO;
        }     

        public int InsertLIBUsersValues()
        {
            return new LIBUsersBO(LIBUsersBEO).InsertLIBUsersValues();
        }

UI layer ( in Submit button)

 protected void btnSubmit_Click(object sender, EventArgs e)
        {

            LIBUsersBEO UserBEO = new LIBUsersBEO()
            {

                LIBUserName = txtUserName.Text,
                LIBPassword = txtPassword.Text,
                LIBUserDOB = Convert.ToDateTime(txtDOB.Text).Date,
                LIBUserSex = ddlUserSex.SelectedValue,
                LIBUserCompanyEmailId = (txtEmailAddress.Text),
                LIBUserCountry = txtCountry.Text,
                LIBSecurityQuestion = ddlSQuestion.SelectedValue,
                LIBSecurityAnswer = txtSAnswer.Text
               
            };

            LIBUsersService UserService = new LIBUsersService(UserBEO);
            int InsertLIBUsersRValue = UserService.InsertUsersRValues();

i Am adding  reference;

Business Layer : Data Access Layer ,BEO

Service Layer  : Business Layer,BEO

Presentation Layer : Service Layer, BEO

This Insert function is working fine,.,. in 3 tier way,

Now am in need, How to retrieve data using Select Store Procedure in LINQ to SQL and Also following 3 tier way,

Help me .,.,.

and aslo send me if u have any sample code , and reference links, and study material,.,.,

thank you,

                   

解决方案

You haven't said what problem you're having, so I can't help you.

One note, though: don't use "try/catch(Exception ex){throw ex;}". Just leave out the try/catch entirely. Your code, as-is, will mess up the stack trace, making it look like the exception occurred in the "throw ex;" statement.


这篇关于使用三层体系结构中的select StoreProcedure检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆