转变? 域对象到 DTO - 无法创建接口实例
您好,我需要在 .Net 和 Flex 表示层之间传递一些对象。
我需要传递并接收以下对象。
public class Room: BasicRoom
{
private int _seatingCap;
private RoomType _roomType;
private IList<Equipment> _equipment;
public virtual RoomType roomType
{
get { return _roomType; }
set { _roomType = value; }
}
public virtual IList<Equipment> equipment
{
get { return _equipment; }
set { _equipment = value; }
}
public virtual int seatingCap
{
get { return _seatingCap; }
set { _seatingCap = value; }
}
目前,我只是将上述(域对象)传递到表示层,这很好。 但是,当我想将对象发送回 .Net 时,我遇到了问题。
因为,我使用 NHibernate 作为 orm 工具,所以它要求我在本例中使用 IList 接口来映射集合。 当我尝试将对象传递回 .Net 时,问题就出现了 - 网关(闪存远程处理 - florineFX)阻止设备被键入为 IList 并引发错误。 “无法创建接口的实例”。
显然我需要将设备键入 List 而不是 IList。
有什么想法可以解决这个问题? 转换为 dto 会更好吗?
有人有这方面的经验吗?
我对 .Net 相当陌生,因此非常感谢任何帮助/指示。
Hi I need to pass some objects to and from .Net and a Flex presentation layer.
I need to pass and recieve the following object.
public class Room: BasicRoom
{
private int _seatingCap;
private RoomType _roomType;
private IList<Equipment> _equipment;
public virtual RoomType roomType
{
get { return _roomType; }
set { _roomType = value; }
}
public virtual IList<Equipment> equipment
{
get { return _equipment; }
set { _equipment = value; }
}
public virtual int seatingCap
{
get { return _seatingCap; }
set { _seatingCap = value; }
}
Currently, I am just passing the above (domain object) to the presentation layer and that is fine.
However, when I want to send the object back to .Net I run into a problem.
As, I'm using NHibernate as the orm tool it requires me to use an interface in this case IList to map collections.
The problem arises when I try to pass the object back to .Net - the gateway (flash remoting - fluorineFX) baulks at equipment being typed as an IList and throws the error.
"Cannot create an instance of an interface".
I obvously need to type equipment to List and not IList.
What are some ideas to get around this?
Would it be better to convert to dto's?
Has anyone had experience with this?
I am fairly new to .Net so any help/pointers much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
列表需要有设置器吗? 通常,集合属性是只读的 - 您只需
添加
/删除
/清除
它们...虚拟
使这变得更棘手 - 通常我会这样做:在这种情况下,也许(因为我们不想在构造函数中调用虚拟方法):
如果这仍然不起作用,请尝试具体的列表类型。
Is there any reason the list needs to have a setter? Often, collection properties are read-only - you just
Add
/Remove
/Clear
them...The
virtual
makes this trickier - normally I'd just do:In this case, perhaps (since we don't want to call a virtual method in the ctor):
If this still doesn't work, try a concrete list type.