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

join问题 #5

Closed
lihong1232 opened this issue Jul 27, 2019 · 1 comment
Closed

join问题 #5

lihong1232 opened this issue Jul 27, 2019 · 1 comment

Comments

@lihong1232
Copy link

    public IQueryable<T1, T2, T3> Join<E1, E2>(Expression<Func<E1, E2, bool>> expression, JoinType join = JoinType.Inner) where E1 : class where E2 : class
    {
        var onExpression = ExpressionUtil.BuildExpression(expression, _param, _prefix, false);
        var table1Name = EntityUtil.GetTable<E1>().TableName;
        var table2Name = EntityUtil.GetTable<E2>().TableName;
        var joinType = string.Format("{0} JOIN", join.ToString().ToUpper());
        if (_tables.Count == 0)
        {
            _tables.Add(table1Name);
            _tables.Add(table2Name);
            Join(string.Format("{0} {1} {2} ON {3}", table1Name, joinType, table2Name, onExpression));
        }
        else if (_tables.Exists(a => table1Name == a))
        {
            _tables.Add(table2Name);
            Join(string.Format("{0} {1} ON {2}", joinType, table2Name, onExpression));
        }
        else
        {
            _tables.Add(table1Name);
            Join(string.Format("{0} {1} ON {2}", joinType, table1Name, onExpression));
        }
        return this;
    }

T1, T2, T3 三个实体 ,为什么表达式只有E1, E2两个参数,不应该有个E3吗?不然E3的表关联关系怎么表达呢?

@soul-soft
Copy link
Owner

通过Join两次就能解决

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

2 participants