google-code-export / dblinq2007

Automatically exported from code.google.com/p/dblinq2007
Other
0 stars 0 forks source link

?? Operator in Column Expression of Join wont work #329

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. make query like this:
var query = from order in db.Order                     //can be null
            join customer in db.Customer on (order.CustomerID??0)equals customer.CustomerID
            select new MyJoinedObject{ order=order, customer=customer };

What is the expected output?
data of Joined Tables

What do you see instead?
Exception: Error.BadArgument("S0701: No way to find left table for Join");
in DbLinq.Data.Linq.Sugar.Implementation.ExpressionDispatcher.AnalyzeJoin

What version of the product are you using? On what operating system?
rev 1411 on 7x64 .Net4, also happens on previous Version 0.20.1

Please provide any additional information below.
DB Looks like this:
                          +---------------+
+-------------------+     |Orders         |
|Customer           |     +---------------+
+-------------------+     |int  #OrderID  |
|int    #CustomerID | --> |int? CustomerID|
|string CustomerName|     +---------------+
+-------------------+

Fixed it like this: (not good but works (for me))
private Expression AnalyzeJoin(IList<Expression> parameters, TableJoinType 
joinType, BuilderContext builderContext)
    {
      if (parameters.Count == 5)
      {
        var leftExpression = Analyze(parameters[0], builderContext);
        var rightTable = Analyze(parameters[1], builderContext) as TableExpression;
        if (rightTable == null)
          throw Error.BadArgument("S0536: Expected a TableExpression for Join");
        var leftJoin = Analyze(parameters[2], leftExpression, builderContext);
        var rightJoin = Analyze(parameters[3], rightTable, builderContext);
        // from here, we have two options to join:
        // 1. left and right are tables, we can use generic expressions (most common)
        // 2. left is something else (a meta table)
        var leftTable = leftExpression as TableExpression;
        if (leftTable == null)
        {
          TableExpression table;
          if (leftJoin.NodeType == ExpressionType.Coalesce)
            table = ((ColumnExpression)((BinaryExpression)leftJoin).Left).Table;
          else if (leftJoin.NodeType == ((ExpressionType)CustomExpressionType.Column))
            table = ((ColumnExpression)leftJoin).Table;
          else
            throw Error.BadArgument("S0701: No way to find left table for Join");
          leftTable= table;
        }
        rightTable.Join(joinType, leftTable, Expression.Equal(leftJoin, rightJoin),
                        string.Format("join{0}", builderContext.EnumerateAllTables().Count()));
        // last part is lambda, with two tables as parameters
        var metaTableDefinitionBuilderContext = builderContext.Clone();
        metaTableDefinitionBuilderContext.ExpectMetaTableDefinition = true;
        var expression = Analyze(parameters[4], new[] { leftExpression, rightTable }, metaTableDefinitionBuilderContext);
        return expression;
      }
      throw Error.BadArgument("S0530: Don't know how to handle GroupJoin() with {0} parameters", parameters.Count);
    }

Original issue reported on code.google.com by sauer1...@gmail.com on 23 Feb 2012 at 12:28

GoogleCodeExporter commented 9 years ago
Seems to be a dupe of 248, sry

Original comment by sauer1...@gmail.com on 23 Feb 2012 at 4:14