本文介绍了Nhibernate和WCF IList<>冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是一个实体



<$公共类Channel:EntityBase
{

[DataMember]
公共虚拟IList< LocalChannel> LocalChannels {get;组; }
}

本地频道有一个字符串属性



这2个类映射流畅,并与许多关系正常工作。



问题出在wcf服务。



当我选择一个频道或所有频道。

localChannels列表是固定的大小。 (返回的ILIst类型是typed数组)

我希望我成为一个List。



Nhibernate不要让我这样写:

  public virtual List< LocalChannel> LocalChannels {get;组; } 

因为无法将他的集合转换为List





任何解决方案?

解决方案

请参阅我的答案



NHibernate投影和DataContract投影是否有是一样的?我不太了解NHibernate,但你可以做这样的事情吗?

  public class Channel:EntityBase {

//对于WCF
[DataMember(Name =LocalChannel)]
private List< LocalChannel>本地通道私人{
获得{返回新的List< LocalChannel>(LocalChannels);}
set {LocalChannels = value;}
}

//对于NHibernate
公共虚拟IList< LocalChannel> LocalChannels {get; set;}
}


i'll use some sample code to demonstrate my problem...

this is an entity

public class Channel : EntityBase
{

    [DataMember]
    public virtual IList<LocalChannel> LocalChannels { get; set; }
}

local channel has a string property.

this 2 classes mapped fluently and works fine with the has many relation.

the problem is in the wcf service.

when i'm selecting a channel or all channels.

the localChannels list is fixed size. (the type of ILIst that returns is typed array)

i want i to be a List.

Nhibernate wont let me to write this:

public virtual List<LocalChannel> LocalChannels { get; set; }

becuase it cant cast his collections to List

and my proxy is written in code and not generated with svcutil so i cant change the collection type.

any solutions?

解决方案

See my answer to Manually change the ClientBase collection type from Array[] to List<>

Does the NHibernate projection and DataContract projection have to be the same? I don't know much about NHibernate, but can you do something like this?

public class Channel : EntityBase{

  //For WCF
  [DataMember(Name="LocalChannel")]
  private List<LocalChannel> LocalChannelsPrivate {
     get {return new List<LocalChannel>(LocalChannels);}
    set {LocalChannels=value;}
  }

  //For NHibernate
  public virtual IList<LocalChannel> LocalChannels {get; set;}
}

这篇关于Nhibernate和WCF IList&lt;&gt;冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 01:38