更新表达式解析不了涉及sqlfunc.iif 和subqueryable 返回
如下
context.updateable<xx>().setcolumns(c=>xx=sqlfunc.iif(sqlfunc.subqueryable<x>().where(d=>d.xx=c.xx).count(),true,false)),where(c=>c.id==xxx).ExecuteCommandAsync()
错误提示(I'm sorry I can't parse the current expression)
热忱回答(6)
-
fate stay night VIP0
2021/9/19提供实体类 和完整的DEMO
0 回复 -
一叶知秋 VIP0
2021/9/19using SqlSugar;
using System;
using System.Collections.Generic;
using System.Text;
namespace SqlSugarDemo
{
class Program
{
static void Main(string[] args)
{
var db = new SqlSugarScope(new SqlSugar.ConnectionConfig()
{
ConnectionString = "server=.;uid=sa;pwd=sasa;database=SQLSUGAR4XTEST",
DbType = DbType.SqlServer,
IsAutoCloseConnection = true
});
db.Updateable<Test001>().SetColumns(c => c.id == SqlFunc.IIF(SqlFunc.Subqueryable<TestPid>().Where(d => d.id == c.pid).Count() > 0, 1, 2)).Where(c=>c.pid==1).ExecuteCommandAsync();
Console.WriteLine("用例跑完");
Console.ReadKey();
}
//建类
public class Test001
{
public int id { get; set; }
public int pid { get; set; }
}
public class TestPid
{
public int id { get; set; }
}
}
}
0 回复 -
一叶知秋 VIP0
2021/9/19想实现的sql如下:
update xx
set xx.x= case when (seelct count(1) from us where name=xx.name) >0 then 1 else 0 end
from
test as xx
where
xx.id in(1,2,3,4)
0 回复 -
fate stay night VIP0
2021/9/19db.Updateable<Test001>().SetColumns(c => c.id == SqlFunc.Subqueryable<TestPid>().Where(d => d.id == c.pid).Select(d=>SqlFunc.AggregateCount(d.id)>0?2:3)).Where(it=>it.id==1).ExecuteCommand();
这样实现, 你上面的表达式不支持解析
0 回复 -
一叶知秋 VIP0
2021/9/19解析错误了
UPDATE [xxx] SET
[xx] =( SELECT TOP 1 ( CASE WHEN ( COUNT( [id] ) > @Const0 ) THEN @MethodConst1 ELSE @MethodConst2 END ) FROM [us ] WHERE ( ( [name] = [c].[name] ) AND ( [age] = @IsOperation3 ) ) ) WHERE ([name] IN ('a','b'))
0 回复 -
fate stay night VIP0
2021/9/19@一叶知秋:那就不支持了,后续我按你的用例试试看
0 回复