从Web API返回nhibernate实体? [英] return nhibernate entity from web api?

查看:68
本文介绍了从Web API返回nhibernate实体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从WebApi返回nHibernate Entity是一个好主意吗?对于简单的实体,我尝试使用它,但复杂的实体呢?在这种情况下,如何处理延迟加载?

Is it a good idea to return nHibernate Entity from WebApi? For simple entity I tried to use this but what about complex entities. How will lazy loading be handled in that case?

推荐答案

可以通过WebAPI返回复杂的实体,但这不是最好的方法,我建议创建一个DTO对象来匹配客户端操作将其映射到NHibernate实体,然后通过API发送.

It is possible to return complex entities via WebAPI, however it is not the best way to do it, what I would suggest is create a DTO object to match the client side operation map it to the NHibernate entity and send it over the API.

关于延迟加载,如果您通过Web API公开对象,则将无用,因为对象序列化了实体的所有属性,并且将从持久性中加载它们,因此实际上在这种情况下,使用延迟加载效率低下.

With regard to the lazy loading, it will have no use if you expose the object via the web API, as the object serializes all the properties of the entity will be accessed and they will be loaded from the persistence, so in fact using lazy loading is inefficient in this scenario.

这篇关于从Web API返回nhibernate实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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