asp.net,ado.net,C#问题 [英] asp.net, ado.net, c# question

查看:60
本文介绍了asp.net,ado.net,C#问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我对c#还是比较陌生,对asp.net和ado.net甚至还比较新.
我正在尝试提高asp.net和ado.net领域的技能.
>
我正在研究一个示例应用程序,我想根据用户从下拉列表中选择的内容在网页中显示项目.

我有两个问题在此学习路径上:

1-是在.aspx文件中完成所有数据库查询和表示",还是在.cs文件中完成了某些查询?

请先感谢.
---------
Jeff

Hello, I''m relatively new to c# and even newer to asp.net and ado.net.
I''m trying to improve my skills in the asp.net and ado.net areas.

I''m working on an a sample app where I want to display items in a web page based on what the user has selected from a drop-down list.

A couple of questions I have while on this learning path:

1 -Are all database queries and "presentation" done within the .aspx files, or are some done in the .cs files?

Thanks in advance.
---------
Jeff

推荐答案

好问题.实际上,您的数据库查询应该来自封装数据库代码的单独dll.微软增加了在ASPX中做数据库工作的方法,但是除了业余爱好者和不知道/不在乎编写好的代码的人之外,没有人使用它们.您应该从已在aspx中输入SQL的任何控件中运行.您应该尝试将数据库代码包装到单独的层中.理想情况下,您的数据库层将不返回数据库对象,而是获取并返回项目中的类列表.

Good question. In fact, your database queries SHOULD come from a seperate dll which encapsulates DB code. Microsoft have added ways to do database stuff in the ASPX, but no-one uses them except hobbyists and people who don''t know/don''t care about writing good code. You should run from any control that has you typing SQL into your aspx. You should try to wrap your database code into a seperate layer. Ideally, your database layer would not return database objects but take and return lists of classes in your project.


Jeff,
我想将我的设计分为三层

1.演示
2.业务逻辑
3.数据库

1.在表示层中,我仅放置那些与UI相关的内容.这将直接进入aspx页面,用户控件(通常是在单独的dll上创建)以及任何与UI相关的逻辑

2.数据库.这是严格与数据库相关的类.没有其他代码属于这里.

3.在业务逻辑中,可以使用不属于这两个类别的任何中间件代码.在创建许多dll方面,我并不发疯.我使用的经验法则是,如果代码可以在其他地方重用,则可以在其逻辑dll中创建它,因此我可以轻松地将其带到另一个项目中并重用.这意味着其他层也可能有多个dll.

同样,我从事过一些项目,它们只有2层或超过3层.它不必只有3层.项目的范围将决定您要如何破坏逻辑设计.在某些情况下,您可能可以摆脱单层的困扰.

Jeff,
I like to break my design into three layers

1. Presentation
2. Business Logic
3. Database

1. In presentation layer I put only those that are of UI related. This will go directly into the aspx pages, user controls (usually I create on separate dll) and any UI related logic

2. Database. This is strictly database related classes. NO other code belongs here.

3. In business logic goes any middle-ware code that does not belong to any of the two categories.

Now, notice how I said ''This goes to separate dll'' in the first case. I don''t go crazy in creating many dlls. The rule of thumb I use is, if the code can be reused somewhere else, then I create it in its logical dll, so I can easily take it to another project and reused. That means the other layers may have multiple dlls as well.

Again, there are projects I have worked which they have only 2 layer or more than 3 layers. It does not have to be only 3 layers. The scope of the project will decide how you want to break your logical designs. In some cases you may be able to get away with single layer.


这篇关于asp.net,ado.net,C#问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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