locked
How to do two level null propagation checks during projection using WCF DS Client? RRS feed

  • Question

  • Hi,

    I cannot get this to work. I am trying to do a Query and project a realated entity and project one of the related entitys related entitiy. Sounds more complex than it is. Here is my code example:

    var query =
        from file in context.Files
        select new File
        {
            ID = file.ID,
            CurrentReminder = file.CurrentReminder == null ? null : new Reminder
            {
                ID = file.CurrentReminder.ID,
                Name = file.CurrentReminder.Name == null ? null : new Name
                {
                    ID = file.CurrentReminder.Name.ID
                }
            }
        };


    The File type has a navigation property CurrentReminder of type Reminder, the property can be null for some File instances. The Reminder type has a Name property of type Name that can be null for some Reminder instances. So I need to have null propagation checks to not break desirialization on the client so I have the == null ? null : construct in the expression.

    The generated OData request is correct and the server returns some File entities with null for Reminder and some with content.

    I get an exception when WCF DS Client is deserializing the response. As far as I can tell the exception occurs on the client when deserializing a File entity that has a CurrentReminder and the CurrentReminder has a Name. The exception thrown states:

    "An entity of type 'Services.OData.Name' cannot be projected because there is already an instance of type 'Services.OData.Reminder' for 'http://localhost/Services.OData.Web/OData.svc/Reminders('21')'."

    It seems as if WCF DS Client got confused of what it is doing and mixing up the types. The full stack trace is:

    System.InvalidOperationException: An entity of type 'Services.OData.Name' cannot be projected because there is already an instance of type 'Services.OData.Reminder' for 'http://localhost/Services.OData.Web/OData.svc/Reminders('21')'. at System.Data.Services.Client.Materialization.ODataEntityMaterializer.ProjectionInitializeEntity(ODataEntityMaterializer materializer, MaterializerEntry entry, Type expectedType, Type resultType, String[] properties, Func`4[] propertyValues) at System.Data.Services.Client.Materialization.ODataEntityMaterializerInvoker.ProjectionInitializeEntity(Object materializer, Object entry, Type expectedType, Type resultType, String[] properties, Func`4[] propertyValues) at _dynamic_ODataEntityMaterializerInvoker_ProjectionInitializeEntity(Object , Object , Type , Type , String[] , Func`4[] ) at lambda_method(Closure , Object , Object , Type ) at System.Data.Services.Client.Materialization.ODataEntityMaterializer.ProjectionInitializeEntity(ODataEntityMaterializer materializer, MaterializerEntry entry, Type expectedType, Type resultType, String[] properties, Func`4[] propertyValues) at System.Data.Services.Client.Materialization.ODataEntityMaterializerInvoker.ProjectionInitializeEntity(Object materializer, Object entry, Type expectedType, Type resultType, String[] properties, Func`4[] propertyValues) at _dynamic_ODataEntityMaterializerInvoker_ProjectionInitializeEntity(Object , Object , Type , Type , String[] , Func`4[] ) at lambda_method(Closure , Object , Object , Type ) at System.Data.Services.Client.Materialization.ODataEntityMaterializer.ProjectionInitializeEntity(ODataEntityMaterializer materializer, MaterializerEntry entry, Type expectedType, Type resultType, String[] properties, Func`4[] propertyValues) at System.Data.Services.Client.Materialization.ODataEntityMaterializerInvoker.ProjectionInitializeEntity(Object materializer, Object entry, Type expectedType, Type resultType, String[] properties, Func`4[] propertyValues) at _dynamic_ODataEntityMaterializerInvoker_ProjectionInitializeEntity(Object , Object , Type , Type , String[] , Func`4[] ) at lambda_method(Closure , Object , Object , Type ) at System.Data.Services.Client.ProjectionPlan.Run(ODataEntityMaterializer materializer, ODataEntry entry, Type expectedType) at System.Data.Services.Client.Materialization.ODataEntityMaterializer.ReadImplementation() at System.Data.Services.Client.MaterializeAtom.MoveNextInternal() at System.Data.Services.Client.MaterializeAtom.MoveNext() at System.Linq.Enumerable.<CastIterator>d__b1`1.MoveNext() 

    Is this a bug in WCF DS Client or should I write the null propagation checks diferent?

    Please note that it Works without null propagation checks for entities that has related entities (but fails for nulls as expected).

    Please also note that if write the Query untyped it also Works. The equivalent untyped Query is:

    var query =
        from file in context.Files.AddQueryOption("$expand", "CurrentReminder,CurrentReminder/Name").AddQueryOption("$select", "ID,CurrentReminder/ID,CurrentReminder/Name/ID")
        select file;
    

    Please help - this is driving me nuts.

    Regards Uffe


    • Edited by Uffe Lauesen Thursday, July 11, 2013 7:05 PM More info added
    Thursday, July 11, 2013 6:19 PM

All replies

  • Hi Uffe,

    Thanks for your post. I've found similar threads about this problem.

    I'll try to involve some other senior engineers in this thread. It will take some time to get the response. Your patience will be appreciated.

    Thanks for your understanding.

    Best regards,


    Chester Hong
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

    Monday, July 15, 2013 5:55 AM
    Moderator
  • Hi,

    Any news on this issue - it has been over a month now? I can see you have released version 5.6.0.0 and the code still fails on that version.

    I would appreciate some help on this one.

    Thanks

    Uffe

    Friday, August 23, 2013 5:50 AM
  • I would really appreciate an answer on this. Is it a bug in WCF DS Client? Will it be fixed.

    Please RESPOND.

    Uffe

    Thursday, October 24, 2013 8:19 PM