ORM将数据映射到对象 [英] ORM mapping data to objects

查看:94
本文介绍了ORM将数据映射到对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用存储过程开发了内部vb.net ORM,以获取数据来填充复杂层次结构中的各个对象.我们已经从每个映射操作的存储过程转移到了在运行时建立并执行的动态sql,这将提高功能和性能.每个类都有自己的映射代码,该属性说明了对db列映射,表,基数等的属性.

我的问题是,由于对象模型的复杂性,由ORM/映射器代码构建的对象可能会调用比所需数量更多的数据,从而影响性能.

对象模型或ORM还是两者都有问题吗?

有人可以提出设计模式/想法来帮助解决此问题吗?

我的最初想法是,我们应该在输出映射类中具有额外的功能,以控制所检索数据的深度,但是我不知道如何做到这一点.关于该主题的任何想法或想法都将得到极大的重视.

解决方案

像Hibernate这样的ORM使用,其中,与任何深度的对象关联均保持原样,但是当层次结构中的对象按需获取时,按需获取首次访问.您可能需要查看代理模式,以了解如何完成此操作.

A inhouse vb.net ORM has been developed using stored procedures to get the data to populate individual objects in a complex hierarchy. We have moved from a stored procedures for each mapping action to dynamic sql which is built up at runtime and executed which should increase functionality and performance. Each class has its own mapping code stating property to db column mapping, table, cardinality etc.

My issue is that due to complexities of the object model, an object being built by the ORM/mapper code will call potentially more data than is needed and thus hamper performance.

Is this an issue with the object model or the ORM or both?

Could anybody suggest a design pattern/idea to help administer this issue?

My first thoughts were that we should have extra functionality in out mapping classes to control the depth of the data retrieved but how could this be achieved cleanly i don't know. any ideas or thought on this subject will be greatly recieved.

解决方案

ORMs like Hibernate deal with this scenario using "Lazy Fetch" strategy where the object associations to any depth are maintained as is, but the objects in the hierarchy are fetched on demand when they are accessed for the first time. You might want to look at Proxy Pattern to get an idea of how this could be done.

这篇关于ORM将数据映射到对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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