Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
GoogleCodeExporter opened this issue Mar 14, 2015 · 1 comment
Open

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

GoogleCodeExporter opened this issue Mar 14, 2015 · 1 comment

Comments

@GoogleCodeExporter
Copy link

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 [email protected] on 23 Feb 2012 at 12:28

@GoogleCodeExporter
Copy link
Author

Seems to be a dupe of 248, sry

Original comment by [email protected] on 23 Feb 2012 at 4:14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant