c#中的三层应用程序 [英] Three layered application in c#

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

问题描述





我在c#winforms中使用3层架构。



我创建了3个不同的项目作为这些层(UI,BLL,DAL)



在UI中引用BLL。

在BLL中引用的DAl。



我已经拥有大约150张桌子的数据库。

有些桌子有超过100个桌子。



我想将数据从UI传递到BLL再传回DAL。



如果我为BLL中的每个表创建类,那将是对于我来说,它是一个混乱的领域。

如果我在BLL中创建类,我可以从UI传递给BLL。但是如何在DAL中创建另一个模型时如何传递给DAL





EF会在这里为我工作吗?

如果有效,我应该将EDMX创建为一个单独的项目吗?或者只是在DAL?



另一个案例是,我的公司有3个让我们。每个位置都有不同的数据库,

但结构相同。

如果我创建EF,我需要在那里选择数据库na。但是它会在我的另一个插座工作吗,当我编译它并在插座上运行设置时?

每个位置的数据库名称和路径可能不同。



请指教。

Jim



我有什么尝试过:



i尝试使用从BLL传递到DAL的参数字段值,但这是一项繁忙的工作。需要更快的解决方案,而无需在DAL中创建另一个模型。



I am using 3 layered architecture in c# winforms.

I have created 3 different projects as these layers (UI, BLL, DAL)

BLL referenced in UI.
DAl referenced in BLL.

I already have the database of having around 150 tables.
Some tables having more than 100 fields.

I want to pass data from UI to BLL to DAL and back as well.

If i create classes for each table in BLL, that will be a mess for me as its lot of fields.
And if i created classes in BLL, i can pass from UI to BLL. But then how to pass to DAL
with out creating another model in DAL?.

Will EF work here for me?
If it works, shall i create the EDMX as a separate project? or simply in DAL?.

Another case is, my company has 3 out lets. Each location is having different database,
but same structure.
If i create EF, i need to select the database there na. But will it work at my another outlet, when i
compile it and run the setup at the outlet?.
The database names and paths may be different in each locations.

Please advise.
Jim

What I have tried:

i have tried using parametric field values passing to DAL from BLL, but its a hectic job. Need a quicker solution to it without creating another model in DAL.

推荐答案

您可以随意使用EF。您可以创建一个新项目,也可以在现有项目中使用它(可能会对现有代码进行调整)。



只是为了给你一个提示, EF使用名为 DbContext 的东西。即使您的数据库中有数百个表,也可以使用少量相关表设置 DbContext



参考您的其他问题,EF通常从.config文件中读取其连接字符串。因此,如果正确设置连接字符串并且数据库服务器具有Internet上的可访问性,则可以通过更改连接字符串来连接任何数据库服务器。如果数据库模式相同,它也可以工作。
You can use EF however you like. You can create a new project or you can use it in an existing one (may be with a tweak with your existing code).

Just to give you a hint, EF uses something called DbContext. Even you have hundreds of tables in your database, you can setup your DbContext with just a handful of related tables.

Referring to your other problem, EF typically reads its connection string from a .config file. So, if you set the connection string correctly and your database servers have accessibility over the Internet, you can connect with any database server by changing the connection string. And if the database schema is same, it will work too.


如果在DAL中定义了模型,则可以重用相同的模型(假设UI使用BLL和BLL使用DAL)模型是足够的。



如果你有数据绑定的可编辑模型,使用相同的模型可能会更容易......我认为这很大程度上取决于应用程序。



如果BLL层基本上返回完整记录并且您的应用程序主要基于CRUD,那么我认为通用模型就足够了。



一般来说,我认为你会在DAL层创建EDMX文件。
You can reuse the same model provided that the model is defined in the DAL (assuming that UI use BLL and BLL use DAL) and that the model is adequate.

Using same model might be easier if you have data-bound editable models... I would think that it depends a lot on the application.

If the BLL layer essentially return full records and your application is mainly based on CRUD, then I would think that a common model is adequate.

Generally, I think you would create the EDMX file in the DAL layer.


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

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