是数据访问层吗? [英] Is it Data Access Layer?

查看:65
本文介绍了是数据访问层吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我可以在DAL中使用此代码吗?还是DAL的一部分?

Hi all,
can i use this code in the DAL? or it can be a part of DAL?

public static DataTable Get(string CommandText, SqlParameter[] Params)
    {
        try
        {
            using (SqlConnection connection = new SqlConnection(Login.getConnection()))
            {
                SqlCommand cmd = new SqlCommand();
               
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = CommandText;
                cmd.Parameters.AddRange(Params);
                cmd.Connection = connection;
                cmd.CommandTimeout = 600;
                connection.Open();

                SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                DataTable dt = new DataTable();
                adapter.Fill(dt);
                return dt;
            }
        }
        catch (Exception ex) { throw ex; }
    }


其中Login.getConnection()仅返回连接字符串.


where Login.getConnection()is just return the connection string.

推荐答案

我不同意.连接字符串必须是DAL的一部分,其余部分是纯DAL代码.即使将其存储在app.config中并一次传递给DAL并存储在此处,连接字符串也必须位于DAL中,其他任何层都不能使用它.
I disagree. The connection string needs to be part of the DAL, and the rest of it is pure DAL code. Even if it''s stored in the app.config and is passed to the DAL once and stored there, the connection string needs to be in the DAL, no other layer should ever use it.


不能,这不是

因为DAL类似于您将其构建为.dll并将其引用到项目编号中.由于您使用的是Login.SqlConnection.将此代码作为DAL的一部分也没有道理


希望这对您有所帮助,并且您同意接受并投票答复,否则将返回您的查询.
--Rahul D.
No this can''t

Because DAL is something like you build it to make .dll and refer it into number of project . Since you are using Login.SqlConnection . It does not make sense either to make this code as part of DAL


Hope this helps and you agree to accept and vote the answer otherwise revert back with your queries.
--Rahul D.


这篇关于是数据访问层吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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