How to Select an Object-Relational Mapping Tool for .NET

How to Select an Object-Relational Mapping Tool for .NET

The single, most important trap to watch out for when choosing an object-relational mapping tool is this: “architecture by product.”

Architecture by product is a term I use to describe a set of symptoms that I’ve seen in projects over the years. In these projects, entire teams would spend months agonizing over product comparison tables, debating the importance and rankings of various features, all without a coherent architecture. Once the product was chosen, the decision was set in stone, and the architecture (when there was one) bent itself around the product. Needless to say, these projects became “never-ending successes.”

When choosing an object-relational mapping tool, you need to understand why you need object-relational mapping and where it will fit into your architecture.

These days, you see three common architecture types in information systems:

  1. Client-Server
  2. Web Application
  3. Smart Client (aka N-Tier)

I’m using these terms somewhat loosely, so I’ll define what I mean by them as well as how object-relational mapping can be used in each of them.

The Client-Server architecture type, also known as Rich Client, involves software running on client machines communicating with a database server. This description does not preclude stored procedures in the database; in fact, at the time of Client-Server popularity, much guidance pointed in exactly that direction. Object-relational mapping fits right in to the architecture type, especially for well-developed domain models. It can save you quite a bit of SQL coding at the very least, and enable elegant handling of complex concurrency behaviors when fully utilized.


Udi1.gif
Click here for a larger image.

Figure 1

Figure 1 illustrates the most basic use of object-relational mapping in this architecture type. User interface elements such as controls and forms make use of business objects that represent the domain model for writing logic while employing objects in the o-r mapping library to persist changes to the database.

A best practice that has come out of this architecture type is to create an intermediary between the UI and the object-relational mapping library. In Domain-Driven-Design lingo, this intermediary is known as a Repository, but its purpose is quite simple: to encapsulate all object-relational mapping code and keep the user interface independent of it. Figure 2 illustrates these new relationships.


Udi2.gif
Click here for a larger image.

Figure 2

The suggested approach of using stored procedures in Client-Server applications can affect your choice of object-relational mapping tool. If you want to employ stored procedures in your database, be aware that many tools do not support mapping against them.

Web applications arose as an alternative to the heavy deployment footprint of Client-Server applications. The interesting point to note is that the server on which Web applications were deployed was a different kind of server than its predecessor. Interestingly, this architecture type holds much in common with Client-Server departing only in where the user interface is shown at runtime, as shown in Figure 3. The HTML shown on the client tier is not architecturally important.


Udi3.gif
Click here for a larger image.

Figure 3

What we have done in this architectural type is to physically replace all the running instances on the various client machines with a single instance on a server machine. If we had developed our repositories and business objects as “stateless”—retrieving all state from the database when needed—they could be easily ported back and forth between Client-Server and Web.

Smart clients are the latest craze in application development, rivaled only by SOA in hype. The thing that separates true N-Tier development (like smart clients) from the previous architectural types is that code that used to run on a single machine must now run, in separate pieces, on different machines. At its most basic level, smart clients entail taking user interface elements and some business logic and running them on a client machine. What isn’t clear, even at this level, is what is left to run on the server. Figure 4 shows the result of taking the previous paradigm and naively applying it under new constraints.


Udi4.gif
Click here for a larger image.

Figure 4

In what way is this architecture lacking? Well, it does not take into account issues of distribution. The interface between repositories and the object-relational mapping library, as well as the business objects was originally designed for in-process communication—a “chatty”interface. The result of exposing such an interface between machines is a drastic drop in performance. It is this kind of architecture that leads to a feature like “Support for remoted data access layer scenarios” in product comparison charts. Figure 5 shows an architecture designed for N-Tier distributed deployment.


Udi5.gif
Click here for a larger image.

Figure 5

To maintain a rich, high-performing UI experience, both repositories and business objects need to be available locally. It is a common misconception that the business objects on the client and those on the server are identical. Each serves different purposes. Business objects developed for the client exist to support UI functionality. This includes providing high quality data-binding capabilities as well as rich validation. Business objects developed for the server exist to encapsulate business rules and cooperate in transactions—transactions managed at the service layer.

There is one topic that has not yet been discussed and is the Achilles heel of object-relational mapping—reporting.

I have yet to see a single application where some kind of reporting was not required. Reporting does not necessarily beginning and ending with reports printed in either Word or PDF format. The basis of reporting is joining data of differing kinds into a single view—this view being primarily read-only. For some reason, once a developer begins using an object-relational mapping tool, all of a sudden he wants to use it for everything—reporting included.

The data used in reporting has no connection whatsoever to objects. First of all, it’s just data—not a single bit of behavior in sight. Secondly, you don’t need all of the data of all entities involved—just a bit of data from each of them. The datatable in .NET suits these needs just fine. So, even though many object-relational mapping tools may enable you to perform complex queries and get back objects, in the case of reporting you just don’t need it. That’s definitely one feature to take off of your product comparison table.

I hope that this discussion has shed some light on the place of object-relational mapping in the bigger scheme of things as well as what capabilities should be developed without it. If you have any comments or questions, please feel free to contact me at Udi@UdiDahan.com.

About the Author

Udi Dahan is a Microsoft Architect MVP, a recognized .NET expert, and manager of the C4ISR Systems Development Group at KorenTec. Udi is known as a primary authority on Service Oriented Architecture in Israel and consults on the architecture and design of large-scale, mission-critical systems developed all

http://www.developer.com/design/article.php/10925_3531871_1

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/111150.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Ubuntu下查看cuda版本的两种方法

    Ubuntu下查看cuda版本的两种方法参考资料:https://blog.csdn.net/qq_16525279/article/details/80662217  在安装Pytorch等深度学习框架的时候,我们往往需要检查是否和cuda版本匹配。在Ubuntu系统下查看cuda版本的方法,我发现有两个。方法一:  比较常用的一个方法是使用如下命令:cat/usr/local/cuda/version.txt使用该命令的效果如下图所示:方法一使用效果方法二:  方法一主要是依据cuda安装时保存的关于版本的txt文件。但

    2022年6月12日
    205
  • 四轴平面机器人的手眼标定

    四轴平面机器人的手眼标定四轴平面机器人的手眼标定介绍在实际的机器人应用中,通常会给机器人配备视觉传感器,视觉传感器用于感知周围环境。但是,通过视觉传感器获取的场景坐标是基于视觉坐标系下的,机器人并不能直接使用,要获取机器人可以直接使用的坐标信息,必须将坐标转换到机器人坐标系下。因此,机器人手眼标定的目的是为了获取从视觉坐标系转换到机器人坐标系的转换矩阵。机器人手眼标定问题可以分为两类:1)eye-in-hand,…

    2022年5月15日
    39
  • 解决ubuntu虚拟机桥接模式下不能上网

    解决ubuntu虚拟机桥接模式下不能上网①sudovim/etc/network/interfaces修改ip和主机在同一网段,gateway和主机一致(ipconfig-all查看主机ip信息)②重启虚拟机,重启之后配置的静态ip才能生效③配置dnssudovim/etc/resolv.conf和主机一直④重启网络sudo/etc/init.d/networkingrestart…

    2022年6月9日
    63
  • slam的核心技术有哪些_遥感技术在农业领域的应用

    slam的核心技术有哪些_遥感技术在农业领域的应用当今科技发展速度飞快,想让用户在AR/VR、机器人、无人机、无人驾驶领域体验加强,还是需要更多前沿技术做支持,SLAM就是其中之一。实际上,有人就曾打比方,若是手机离开了WIFI和数据网络,就像无人车和机器人,离开了SLAM一样。什么是SLAMSLAM的英文全称是SimultaneousLocalizationandMapping,中文称作「同时定位与地图创建」。SL…

    2022年9月30日
    3
  • Pytest(16)随机执行测试用例pytest-random-order「建议收藏」

    Pytest(16)随机执行测试用例pytest-random-order「建议收藏」前言通常我们认为每个测试用例都是相互独立的,因此需要保证测试结果不依赖于测试顺序,以不同的顺序运行测试用例,可以得到相同的结果。pytest默认运行用例的顺序是按模块和用例命名的ASCII编码

    2022年7月31日
    4
  • 我用kafka两年踩过的一些非比寻常的坑

    我用kafka两年踩过的一些非比寻常的坑

    2022年2月18日
    40

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号