使用 NHibernate 和上下文更改数据库设计分层应用程序
我正在设计一个 C# 应用程序
- 演示(网站 + Flex 应用程序)
- 业务逻辑层(可能是 WCF 以启用多客户端平台)
- 数据访问层(使用 NHibernate)
我们将把我们的解决方案集成到许多预先存在的客户端数据库环境中,我们想在 DAL 中使用 NHibernate。我的同事指出,使用 NHibernate 从客户端的数据库(如用户或图像)生成类会导致 BLL 在每次数据库更改时在我们面前爆炸! 那么问题是我们如何防止这种情况发生? 我们正在考虑使用 AutoMapper 创建业务对象并将 NHibernate 对象映射到这些 BO(嗯,这会使它们成为 DTO 吗?),并防止 dal 更改影响 BLL。这是要走的路吗?
谢谢 !
编辑:
为了更好地理解我们想要实现的目标,您可能需要上下文: 我们主要为我们公司在前端使用 Flex 构建一个照片存储/共享应用程序,在后端使用 C# 构建,因此我们处理代码和数据库的各个方面。
但是:该产品也可以按等级购买,最终已经拥有包含用户表或图像表的数据库。我在这里想到一个新的潜在客户,他有一个包含几亿行的图像表,并且由于表的更改时间太长,因此不会为我们的业务逻辑添加列。
尽管这是可能的(例如,由于行数较少,可以修改用户表),但每次我们必须集成到 BLL 的层数据库中时,我们都会问自己如何处理表结构更改,而不影响我们的所有解决方案到 Flex 中的客户端应用程序!
I'm designing a C# application
- Presentation ( web site + flex apps )
- Business Logical Layer (might be WCF to enable multi client platforms)
- Data Access Layer ( With NHibernate )
We're going to integrate our solution in many preexistant client's database environnements and we would like to use NHibernate in the DAL.. My colleague pointed out that generating classes from client's DB (like User or Image) with NHibernate would cause the BLL to blow up in our face at each DB changes !
So the question is how do we prevent that from happening ?
We're thinking about creating business objects and map NHibernate objects to these BO (hum, does that make them DTOs ?) with AutoMapper and prevent dal changes from affecting BLL.. Is this the way to go ?
Thanks !
EDIT :
To give a better understanding of what we're trying to achieve, you might need context :
We're building a photo storing/sharing app in Flex for the front-end and C# on the back-end mainly for our company, so we handle every aspects of the code and DB.
But : that product can also be bought by tiers, which eventually have already a database with User table or Image table. I'm thinking here about a new prospect who have an Image table with a few hundred millions of rows and adding columns for our business logic isn't going to be happening because of a too long ALTERing of the table.
Even though it would be possible (User table for example can be modified because of lesser rows), we're asking ourselves how to handle table structure changes without impacting all of our solution each time we have to integrate in a tier database, from BLL to client app in Flex !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据我的经验,您的业务对象(又名域对象)应该在 OO 中建模,以代表您现实生活中的业务实体和第三范式的表(这可能会根据您追求速度与文件大小的设计而改变)
NHibernate 应该映射使用其映射文件在 BO 和表之间进行操作。
现在您有合法的情况:
我怀疑是否存在全面推理,但是我希望这些示例能让您思考这一点
我还没有尝试过跨多个数据库的 NH,也应该 每个数据库都有自己的服务?
这里有一些链接
希望这有帮助
in my experience, your business objects (AKA Domain Objects) should be modelled in OO to represent your real life business entities and your tables in 3rd normal form (this may change depending on what design you are after speed vs file size)
NHibernate should map between your BO's and Tables, using its mapping files.
now you have legitimate cases:
I doubt there is a blanket reasoning, however I hope the examples make you think about this
I have not tried NH accross multiple Db's, also should each database have its own service on top?
here are some links
Hope this helps
听起来您想将域模型设计为与数据库无关。我也对拥有可以映射到多个不同数据库模型的中心域模型的最佳方法感兴趣。
您建议的方式,即使用代码生成器从每个数据库创建 DTO,可能是一种选择。另一种方法是为每个预先存在的数据库创建自定义 NHibernate 映射。您可能仍然需要使用一些 DTO 来降低某些映射的难度,但它可能会给您更多的控制权。
这些只是一些想法。更有经验的 NHibernate 用户可能会对您的情况有更好的了解。
It sounds like you want to design your domain model to be database agnostic. I too am interested in the best approach to having a central domain model that can map over to multiple different database models.
The way you are proposing, to create DTO's from each database using code generators, could be an option. Another would be to create custom NHibernate mappings for each preexisting database. You still may need to use some DTOs to make some of the mappings less difficult but it may give you more control.
These are just some thoughts. More experienced users with NHibernate probably will have better insight to your situation.