R – Nhibernate and WCF IList<> Conflict

fluent-nhibernatewcf

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?

Best Answer

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;}
}
Related Topic