locked
Outer join issues RRS feed

  • Question

  • I have a pair tables that I would like to retrieve, one has the order status, the second has a translation in it.  It's done with DataServiceQuery<> and AddQueryOptions $extend to retrieve the translations.

    Problem is the following...

    LogException: System.ArgumentNullException: Value cannot be null.
    Parameter name: second
    at System.Linq.Enumerable.Except[TSource](IEnumerable`1 first, IEnumerable`1 second, IEqualityComparer`1 comparer)
    at System.Data.Services.Client.MaterializeAtom.ReadNext(ClientType currentType, Type expectedType, AtomParseState atom, EntityStates& entityState, Object& currentValue)
    at System.Data.Services.Client.MaterializeAtom.MoveNext()
    at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
    at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)

    It seems that when the second table is empty then Data Services coughs this up.  Anyone else get the same problems?

    Monday, December 29, 2008 8:45 AM

Answers

  • Indeed, nail on the head.

    The problem seems to be that if I have an expand on a nullable property and it's the only entry in the expand then it throws.  If I add it to another expand then it works fine.

    So (changing the syntax slightly)...

    .Expand("Order/OrderType").Expand("Order/Customer")

    would throw an error if Customer can be null (and is null)
    whereas

    .Expand("Order/OrderType,Order/Customer")

    seems to be fine.
    Thursday, April 16, 2009 12:04 AM

All replies

  • Hi ,
     Can you share the client code snippet that is causing this error and also the value of the DataServiceContextInstance.MergeOption right before the query ?

    Phani Raj Astoria
    Monday, December 29, 2008 6:34 PM
    Moderator
  •  Here's the code, line 20 throws the error

    1         List<SupplierStockOrderType> _supplierStockOrderTypes = null;     
    2         public List<SupplierStockOrderType> SupplierStockOrderTypes     
    3         {     
    4             get    
    5             {     
    6                 object thislock = new object();     
    7     
    8                 if (_supplierStockOrderTypes == null)     
    9                 {     
    10                     lock (thislock)     
    11                     {     
    12                         // fill it with an empty collection while we populate it     
    13                         _supplierStockOrderTypes = new List<SupplierStockOrderType>();     
    14     
    15                         _ctx.MergeOption = MergeOption.OverwriteChanges;     
    16                         DataServiceQuery<SupplierStockOrderType> q = _ctx.CreateQuery<SupplierStockOrderType>("SupplierStockOrderType");     
    17                         q = q.AddQueryOption("$expand""SupplierStockOrderTypeLoc");     
    18                         q.BeginExecute(delegate(IAsyncResult ar)     
    19                         {     
    20                             SupplierStockOrderTypes = q.EndExecute(ar).ToList();     
    21                         }, null);     
    22                     } // lock     
    23                 }     
    24                 return _supplierStockOrderTypes;     
    25             }     
    26             set    
    27             {     
    28                 _supplierStockOrderTypes = value;     
    29                 OnPropertyChanged("SupplierStockOrderTypes");     
    30             }     
    31         }     
     

    Monday, December 29, 2008 7:46 PM
  • Hi ,
     Change
    15                         _ctx.MergeOption = MergeOption.OverwriteChanges;

    to
    15                         _ctx.MergeOption = MergeOption.AppendOnly;

    and see if the error repro's
    Phani Raj Astoria
    Monday, December 29, 2008 9:50 PM
    Moderator
  •   No, no difference, the error is still thrown.  At the moment it's ok because I just stick some data in the Loc table and things work.  Longer term this could cause problems.
    Tuesday, December 30, 2008 7:50 PM
  • Sorry, changing the MergeOption does make a difference.  Problem is that appending the entities means the etag does not get updated and I can't edit the entity and post it back.

    I'm going round in circles a bit on this one at the moment...

    Here's the scenario, I have a list box which displays some data from a table, lets say Orders.  An order can have a number of OrderLines.  An OrderLine has a OrderLineType, like Part, Labour etc.  If I display the Orders in a list and then select one, the order is displayed in full and the order lines are displayed in a grid.  Now when the Orders were selected for the list the $expand option was used to get OrderLines.  When the Order is displayed in full you need to expand out the OrderType for each OrderLine.  (This may be a poor example but for arguments sake say you need to lazy load it.)

    At the moment I don't see any way of expanding the OrderType without calling BeginLoadProperty for each of the lines, there's no way to batch them all up together.  I tried just making a batch to return all of the references but it didn't seem to update the entity.

    I'm interested to know if there is something I'm missing on this.  A LoadProperties method on the client entity would be nice.
    Friday, January 9, 2009 9:24 PM
  • Hello,

    Could you try the following (deep expand):

      DataServiceQuery<SupplierStockOrderType> q = _ctx.CreateQuery<Orders>("Orders");     
     q = q.AddQueryOption("$expand""OrderLines, OrderLines/OrderType"); 


    Regards,
    Monica
    Monday, January 12, 2009 11:01 PM
    Moderator
  • I get problems with this because I use MergeOption OverwriteChanges and this throws an (apparently already known) error with duplicate key in the entities collection.
    Tuesday, January 13, 2009 4:29 AM
  • Indeed, nail on the head.

    The problem seems to be that if I have an expand on a nullable property and it's the only entry in the expand then it throws.  If I add it to another expand then it works fine.

    So (changing the syntax slightly)...

    .Expand("Order/OrderType").Expand("Order/Customer")

    would throw an error if Customer can be null (and is null)
    whereas

    .Expand("Order/OrderType,Order/Customer")

    seems to be fine.
    Thursday, April 16, 2009 12:04 AM