c#中的三层架构 [英] Three tier architecture in c#

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

问题描述

您好b $ b

我使用C#开发Windows窗体项目。

我使用3层架构(UI层,业务逻辑,数据访问) 。



我有一张名为顾客的桌子,里面有大约100个字段。



我想要添加新客户,将所有这100个字段分配到业务层客户类,然后调用业务层的insertCustomer方法。



现在,从业务层开始,经过所有验证后,我如何将整个客户类一起传递到数据访问层,以便我可以使用所有字段值进行实际的插入查询?



或者我是否需要将每个字段分配到变量中并将这些变量作为参数从业务层传递到数据访问层?



我希望,还有一些简单的方法。

请指导我。

谢谢

Jim



我的尝试:



我已经尝试在业务层中实例化类并将其传递给数据层。

但是没有工作,因为它创建了新实例。

Hi
I using C# and developing a windows forms project.
I am using 3 tier architecture (UI layer, Business Logic, Data Access).

I have a table named "Customer" of having around 100 fields in it.

I want to add new Customer, am assigning all these 100 fields into the Business Layer "Customer Class", then calling a "insertCustomer" method of business layer.

Now, from business layer, after all validations, how can i pass the whole "customer" class together into Data access layer, so that i can make the actual insert query with all field values?.

or do i need to assign each field into variables and pass these variables as parameters from business layer to data access layer?..

I hope, there must be some another easy way.
Kindly guide me.
Thanks
Jim

What I have tried:

I have tried instantiating the class in the business layer and pass it to data layer.
but not working as it creates new instance.

推荐答案

Hi Jim,
    
    You just need to pass the customer object to your Data Access Layers method.

public class Customer
{
   field1; field2;.... field100;
}

Business layer:
public someMethod{
Customer objCust = new Customer ();
objCust.field1 = val1;
.
.
.
objCust.field100 = val100;

DAL.test(objCust);
}


DAL:

public test(Customer objCust)
{
   Your Database Operations...
}


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

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