Stop WCF Deserializing Empty ICollection to Zero-Capacity Array

I have a problem using WCF and Entity Framework 4.1 POCO objects (generated using T4 templates). My main problem is that when sending a POCO object from my client to the WCF service, it deserializes the member variable of type ICollection as a fixed-size array.

On the client side, I can say that visual studio uses IList instead of T [] - but I can’t see an option like this on the server side.

This does not cause problems with several things, such as storing these objects in a database.

Is it possible to tell WCF what type of object to deserialize ICollection (or any array) like?

+5
source share
2

, , , POCO, EF T4, WCF. , , , - :

: " / Datalayer.Customers. . InnerException."

InnerException: " " Datalayer.Order [] ".

, , , , , , T4 HashSet ICollection. , , , .

+5

Entity Framework 6, , T4.

,

navProp.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many ? ("ICollection<" + endType + ">") : endType,

to

navProp.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many ? ("List<" + endType + ">") : endType,

, , - , .ToList().

this.<#=code.Escape(navigationProperty)#> = new HashSet<<#=typeMapper.GetTypeName(navigationProperty.ToEndMember.GetEntityType())#>>();

this.<#=code.Escape(navigationProperty)#> = new HashSet<<#=typeMapper.GetTypeName(navigationProperty.ToEndMember.GetEntityType())#>>().ToList();

HashSet < > . ToList() , , , System.Linq, UseDirectives:

    public string UsingDirectives(bool inHeader, bool includeCollections = true)
{
    return inHeader == string.IsNullOrEmpty(_code.VsNamespaceSuggestion())
        ? string.Format(
            CultureInfo.InvariantCulture,
            "{0}using System;{1}" + Environment.NewLine +
            "{0}using System.Linq;" + 
            "{2}",
            inHeader ? Environment.NewLine : "",
            includeCollections ? (Environment.NewLine + "using System.Collections.Generic;") : "",
            inHeader ? "" : Environment.NewLine,
            Environment.NewLine)
        : "";
}
+1

All Articles