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

在仓储模式下使用子查询,生成的sql语句表别名会混淆两个表的字段 #1761

Open
llyone opened this issue Mar 27, 2024 · 1 comment

Comments

@llyone
Copy link

llyone commented Mar 27, 2024

问题描述及重现代码:

在仓储模式下使用子查询,生成的sql语句表别名会混淆两个表的字段如 a表的code1字段变成了b表的code1,只有指定某个表的别名,同时保证子查询的lambda表达式参数名称与别名一致才能正常生成sql,不一致的情况下不只是混淆表明与字段的关系还会冒出第三个别名。。

//异常代码

var select = ARepository.Where(filter);
if (flag)
{
    var bSelect = new BRepository().Where(n => !string.IsNullOrEmpty(n.Code));

    if (flag1)
    {
        select.Where(m => bSelect.Where(x => x.Code1 == m.Code).Any());
    }
    else
    {
        select.Where(m => bSelect.Where(x => x.Code1 != m.Code).Any());
    }
}




//可正常使用代码
var select = ARepository.Where(filter);
if (flag)
{
    var bSelect = new BRepository().Select.As("b").Where(n => !string.IsNullOrEmpty(n.Code));

    if (flag1)
    {
        select.Where(m => bSelect.Where(b => b.Code1 == m.Code).Any());
    }
    else
    {
        select.Where(m => bSelect.Where(b => b.Code1 != m.Code).Any());
    }
}



// c# code

image

数据库版本

mysql 5.7

安装的Nuget包

freesql 3.2.812

.net framework/. net core? 及具体版本

.net8

@2881099
Copy link
Collaborator

2881099 commented Mar 27, 2024

建议习惯性使用 a b c 区分别名

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