n层架构问题。 [英] n-tier architecture problem.

查看:79
本文介绍了n层架构问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在asp.net网站上进行n层架构。??

i尝试但未正确引用图层

 {Dll,Entities,Dal和网站项目。} 



i是这样的。

 dal有实体,
bll有实体和Dal ,
实体没有图层引用,
网站有实体,bll作为参考。
,但是当我尝试用bll写
时;
使用实体;





bll未显示在intellisense中并给出错误。

但是dll并且实体没有给出错误。

i再次重新开始这个。

但是遇到同样的问题。



i不能在default.aspx.cs中使用bll

必定有问题。

请帮忙。

解决方案

< blockquote>是的,你可以。

首先,创建一个Repository类。把它放在DAL文件夹中。存储库构造函数将实例化您拥有的实体模型的对象(上下文)。它将包含用于检索,保存和更新数据的所有方法。

接下来,创建一个BLL文件夹并放置所有扩展的部分类和您创建的所有其他类,这些类将用于根据传入的参数决定哪些数据返回到内容页面。这些方法将实例化存储库的对象并调用存储库方法。如果一个类访问存储库然后对数据执行任何操作,如parse,filter,send in参数,它应该在BLL中。

三,在你的内容页面上,使用ObjectDataSource控件来附加BLL类和方法的选择,更新,删除方法。主题很大,不适合初学者,但要学习并做到这一点!这将是非常值得的。



内容页面中ObjectDataSource控件标记的示例:

 <   asp:objectdatasource     id   =  ImagesObjectDataSource    runat   =  server    typename   =  BLL.ImageData    xmlns:asp   = #unknown >  
DataObjectTypeName =BLL.ImageData SelectMethod =GetAllPhotosDeleteMethod =DeleteIma ge
UpdateMethod =UpdateImageOnUpdated =ImagesObjectDataSource_UpdatedOldValuesParameterFormatString =orig {0}
OnUpdating =MappImagesObjectDataSource_UpdatingOnDeleted =ImagesObjectDataSource_Deleted
ConflictDetection =CompareAllValues>
< SelectParameters >
< asp:querystringparameter 名称 = imageID < span class =code-attribute> querystringfield = imageID type = 字符串 / >
< / SelectParameters >
< updateparameters >
< asp:参数 名称 = ImageData type = 对象 / >
< asp:parameter name = origImageData type = 对象 / >
< ; / updateparameters >
< / asp:objectdatasource >



从ObjectDataSources的DataObjectTypeName和TypeName属性可以看出它们连接到BLL.ImageData类。 BLL.ImageData类具有获取和处理从调用存储库方法返回的数据的方法。



这是ASP.Net网站N-Tier的坚果壳。当然有很多实现。但是你的逻辑层就在那里。



搜索使用ObjectDataSource控件获取更多信息。






更改图层类的访问修饰符。



通常我建议



DAL类和方法是内部的,因此只能使用Same NameSpace访问



  internal   class  DataLayer 
{
internal static void SaveToDB( string query)
{

}
}





和BAL方法是公开的,因此您可以通过添加'使用BAL来访问Webform ;'

  public   class 员工
{
public 无效 AddEmployee()
{
}
}







谢谢



Siva Rm K


can i do n-tier architechtur in asp.net websites.??
i tried but failed in referencing correctly layers

{Dll,Entities,Dal and website project.}


i did like this.

dal has entity,
bll has entity and Dal,
entity has no layer reference ,
website has entity and bll as referece .
 but when i try to write
using bll;
using entity;



bll is not shown in intellisense and gives error.
but dll and entity gives no error.
i did this again starting over all again.
but getting same problem.

i cant use bll in default.aspx.cs
there must be something wrong.
help please.

解决方案

Yes you can.
First, create a Repository class. Put it in the DAL folder. The repository constructor will instantiate an object(context) of the Entity model you have. It will contain all the methods you use to retrieve, save and update data.
Next, create a BLL folder and place all your extended partial classes and all other classes you created that will be used to decide which data to return to the content page based on passed in parameters. These methods will instantiate an object of the repository and the call the repository methods. If a class accesses the repository and then does anything with the data like parse, filter, send in parameters, it should be in the BLL.
Third, On your content pages, use the ObjectDataSource control to attach the select, update, delete methods to the BLL classes and methods. The topic is large and not for beginners, but learn it and do it! It will be well worth it.

Example of the ObjectDataSource control markup in content page:

<asp:objectdatasource id="ImagesObjectDataSource" runat="server" typename="BLL.ImageData" xmlns:asp="#unknown">
        DataObjectTypeName="BLL.ImageData" SelectMethod="GetAllPhotos" DeleteMethod="DeleteImage"
        UpdateMethod="UpdateImage" OnUpdated="ImagesObjectDataSource_Updated" OldValuesParameterFormatString="orig{0}"
        OnUpdating="MappImagesObjectDataSource_Updating" OnDeleted="ImagesObjectDataSource_Deleted"
        ConflictDetection="CompareAllValues">
        <SelectParameters>
            <asp:querystringparameter name="imageID" querystringfield="imageID" type="String" />
        </SelectParameters>
        <updateparameters>
            <asp:parameter name="ImageData" type="Object" />
            <asp:parameter name="origImageData" type="Object" />
        </updateparameters>
    </asp:objectdatasource>


As you can see from the ObjectDataSources' DataObjectTypeName and TypeName properties that they are connected to the BLL.ImageData class. The BLL.ImageData class has methods to get and process the data returned from calling repository methods.

That is ASP.Net web site N-Tier in a nut shell. Of course there are many implementations. But your logical layers are there.

Search for using the ObjectDataSource control for more information.


Hi,

Change the Access modifiers for your Layer Class.

Normally i suggest

DAL Classes and methods are internal ,So only access with in Same NameSpace

internal class DataLayer
{
  internal static void SaveToDB(string query)
  {
    
  }
}



And BAL Methods are Public, so you can access in Webform by adding 'using BAL;'

public class Employee
{
 public void AddEmployee()
 {
 }
}




Thanks

Siva Rm K


这篇关于n层架构问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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