LINQ Query Expression Fails in VB with 'Coalesce' Not Supported Error, C# OK RRS feed

  • Question


    Here's another VB-specific problem with ADO.NET Data Services:


    ' Query fails with "The expression type Coalesce is not supported." exception

    Dim entities As New NorthwindEntities(url)

    Dim query = From o In entities.CreateQuery(Of Order)("Orders") _

    Where o.ShipCountry = "USA" AndAlso o.Freight >= 500 _

    Order By o.OrderDate Descending _

    Select o

    For Each o As Order In query

    sbResult.Append(String.Format("OrderID = {0}, ShipName = {1}, ShippedDate = {2Big Smile}, Freight = {3:c} " & vbCrLf, o.OrderID, o.ShipName, o.ShippedDate, o.Freight))

    Next o


    The following C# expression works like a champ from the same Northwind instance:


    NorthwindEntities entities = new NorthwindEntities(url);

    var query = from o in entities.CreateQuery<Order>("Orders")

    where o.ShipCountry == "USA" && o.Freight >= 500

    orderby o.OrderDate descending

    select o;

    foreach (Order o in query)


    sbResult.Append(String.Format("OrderID = {0}, ShipName = {1}, ShippedDate = {2Big Smile}, Freight = {3:c} \r\n", o.OrderID, o.ShipName, o.ShippedDate, o.Freight));



    I assume this is an issue with VB null handling as reported in LINQ and Entity Framework Posts for 2/11/2008+:


    Stefan Sedich Discovers Cause of Slow LINQ to SQL Performance with VB

    Stefan's Different SQL between VB.NET and C# LINQ to SQL SOLVED!! post of February 12, 2008 describes the cause of VB's added (COALESCE(CASE ... )) clauses: VB treats database fields that allow nulls differently from C#. Note that Northwind tables allow nulls in foreign-key fields that would throw referential integrity exceptions if set to null.


    Is this a known problem? Are there workarounds?



    Wednesday, February 13, 2008 9:13 PM



    Coalesce expressions are currently not supported with Linq To Astoria.  It is on the feature list and should be in sp1 beta of VS 2008.



    Thursday, February 14, 2008 12:06 AM