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

UseGenerateCommandParameterWithLambda(true)时子语句的参数没整合到主语句 #231

Closed
tky753 opened this issue Mar 12, 2020 · 6 comments

Comments

@tky753
Copy link
Contributor

tky753 commented Mar 12, 2020

[Table(Name = "EDI")]
public class Edi
{
    [Column(Name = "EDI_ID")] public long Id { get; set; }
}

[Table(Name = "EDI_ITEM")]
public class EdiItem
{
    [Column(Name = "EDII_ID")] public long Id { get; set; }
    [Column(Name = "EDII_EDI_ID")] public long EdiId { get; set; }
}

......

var itemId = 1;
var edi = fsql.Select<Edi>()
    .Where(a=>fsql.Select<EdiItem>().Where(b=>b.Id==itemId).Any())
    .First(a=>a);

会报 必须声明标量变量 "@exp_0"
看DbCommand中 参数个数为0
生成sql没有问题。

SELECT TOP 1 a.[EDI_ID] as1
FROM [EDI] a
WHERE (exists(SELECT TOP 1 1
        FROM [EDI_ITEM] b
        WHERE (b.[EDII_ID] = @exp_0)))
@2881099
Copy link
Collaborator

2881099 commented Mar 12, 2020

好的,UseGenerateCommandParameterWithLambda 可能还有其他问题存在

@2881099
Copy link
Collaborator

2881099 commented Mar 12, 2020

#200 的问题我回复了,看一下 @tky753

@tky753
Copy link
Contributor Author

tky753 commented Mar 12, 2020

回复了,
稍微更正一下,sql因该也是有点问题的

var id = 1; //主语句变量
var itemId = 1; //子语句变量
var edi = fsql.Select<Edi>()
    .Where(a=>a.Id == id)
    .Where(a=>fsql.Select<EdiItem>().Where(b=>b.Id==itemId).Any())
    .First(a=>a);
            WriteLine(edi.Id);
SELECT TOP 1 a.[EDI_ID] as1 
FROM [EDI] a 
WHERE (a.[EDI_ID] = @exp_0) AND (exists(SELECT TOP 1 1 
	FROM [EDI_ITEM] b 
	WHERE (b.[EDII_ID] = @exp_0)))
--两个都是@exp_0了

@2881099
Copy link
Collaborator

2881099 commented Mar 12, 2020

这是一个问题,只要把两个 IFreeSql._dbParams 弄成一个引用就好了

@2881099
Copy link
Collaborator

2881099 commented Mar 12, 2020

var itemId2 = 2;
var itemId = 1;
var edi = g.sqlite.Select<Edi>()
   .Where(a => a.Id == itemId2 && g.sqlite.Select<EdiItem>().Where(b => b.Id == itemId).Any())
   .First(a => a); //#231
SELECT a."EDI_ID" as1 
FROM "EDI" a 
WHERE (a."EDI_ID" = @exp_0 AND exists(SELECT 1 
	FROM "EDI_ITEM" b 
	WHERE (b."EDII_ID" = @exp_1) 
	limit 0,1)) 
limit 0,1

2881099 pushed a commit that referenced this issue Mar 12, 2020
2881099 pushed a commit that referenced this issue Mar 12, 2020
@tky753
Copy link
Contributor Author

tky753 commented Mar 12, 2020

圆满了

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