在返回的DataTable或数据集从DAL是错误的做法 [英] Is returning DataTable or DataSet from DAL is wrong approach

查看:282
本文介绍了在返回的DataTable或数据集从DAL是错误的做法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从头开始创建我的任务项目,我通过创建一个处理连接到SQL,并可以执行存储过程的DAL开始了。

项目后期将是一个CMS或博客

我的DAC或DAL读取从的web.config 连接字符串,并接受 SQL参数阵列以及存储过程名称,并在数据表返回执行存储过程的输出。

我打电话给我的DAC如下(使用类函数有时使用code后面)

I am creating my assignment project from scratch, I started off by creating a DAL that handles connection to SQL and can execute stored procedure.
The project later will be a CMS or Blog
My DAC or DAL is reading connection string from web.config and accepting arrays of SQL Parameters along with Stored Procedure Name and is returning output of the executed stored procedure in DataTable.
I am calling my DAC as follows(using class functions and sometimes using code behind)

Dim dt As DataTable = Dac.ReturnDataTable("category_select_bypage",  New SqlParameter("@pageid", pageid), New SqlParameter("@id", id))

这是工作的罚款,我假设通过调用该DAC来完成我的整个应用程序,插入并使用存储过程检索数据或更高版本可能是简单的查询。

但是,我已经表明这项工作给我的老师,他告诉的我,您使用的是一种错误的做法和你的code未履行正确的DAL方法。

所以,我现在太有DAL和DAC混淆。任何这里怎么是主要的问题。


1.什么是真正的DAL和DAC
之间的区别
2.通过使用我的方法,什么样的应用是很好的做呢?使用这种方法我可以做的购物车?
3.什么是错我的做法?

Which is working fine and i am assuming to complete my whole application by calling this DAC and insert and retrieve data using stored procedures or may be simple queries later.
But, i have showed this work to my teacher and he told's me that you are using a wrong approach and your code is not fulfilling the correct DAL approach.
So, i am now too much confused with DAL and DAC. Any How here are main questions.

1. What really is the difference between DAL and DAC
2. By using my approach, what kind of application is good to make with it ? Can i make shopping carts using this approach? 3. What is wrong with my approach ?

推荐答案

阿德里亚诺提供了一个很好的联系。当然,一本必读书。但我看到的一件事。当一个应用程序创建逻辑层,每层不知道那些它下面的内部运作。例如,presentation层不知道的数据层如何获取数据,它只是魔术。这样做的原因是,如果你决定什么不​​使用SqlClient,选择了不同的技术。现在,通过使用技术隐藏使用层可以使这种改变很容易。

Adriano provided a very good link. Certainly a must read. But I do see one thing. When creating logical layers in an application, each layer is not aware of the inner workings of those beneath it. For example the presentation layer has no idea how the data layer gets data, it just magic. The reason for this is what if you decide to not use the SqlClient and chose a different technology. Now by using "Technology Hiding" with layers you can make that change quite easily.

所以给你有什么我假设的DataTable是在presentation(或应用)层。而且,如果这是真的你DAC方法调用不应该暴露有关什么,或者它是如何获取数据什么。你的情况,这个规则是由参数的SqlParameter侵犯。也许你可以通过字符串的或者int的。例如:

So given what you have I'm assuming the DataTable is in the presentation (or application) layer. And, if this is true your DAC method call should not expose anything related to what or how it is retrieving data. In your case this rule is violated by the SqlParameter parameter. Perhaps you could pass string's or int's. For example:

public DataTable Dac.GetPage(int pageId, int id)

从来没有少,最好的运气。我很高兴地看到那些愿意学习和那些愿意教。

Never the less, best of luck. I'm glad to see those willing to learn and those willing to teach.

这篇关于在返回的DataTable或数据集从DAL是错误的做法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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