子查询ToList报错 返回

public class TestView : Test0
{
public List<Test1View> Test1V { get; set; }
}
public class Test1View
{
public long Test0Id { get; set; }
public string Title1 { get; set; }
}
[SugarTable("test_0")]
public class Test0
{
[SugarColumn(IsNullable = false, IsPrimaryKey = true)]
public long Id { get; set; }
public string Title { get; set; }
}
[SugarTable("test_1")]
public class Test1
{
[SugarColumn(IsNullable = false, IsPrimaryKey = true)]
public long Id { get; set; }
[SugarColumn(ColumnName = "test0id")]
public long Test0Id { get; set; }
public string Title1 { get; set; }
}
public static void Test(SqlSugarScope db)
{
db.Deleteable<Test0>().ExecuteCommand();
db.Deleteable<Test1>().ExecuteCommand();
db.Insertable(new Test0 { Id = 1, Title = "111111" }).ExecuteCommand();
db.Insertable(new Test1 { Id = 1, Test0Id = 1, Title1 = "111111" }).ExecuteCommand();
db.Insertable(new Test1 { Id = 2, Test0Id = 1, Title1 = "111111" }).ExecuteCommand();
db.Insertable(new Test1 { Id = 3, Test0Id = 1, Title1 = "111111" }).ExecuteCommand();
db.Insertable(new Test1 { Id = 4, Test0Id = 1, Title1 = "111111" }).ExecuteCommand();
db.Insertable(new Test1 { Id = 5, Test0Id = 1, Title1 = "111111" }).ExecuteCommand();
db.Insertable(new Test1 { Id = 6, Test0Id = 2, Title1 = "111111" }).ExecuteCommand();
db.Insertable(new Test1 { Id = 7, Test0Id = 2, Title1 = "111111" }).ExecuteCommand();
db.Insertable(new Test1 { Id = 8, Test0Id = 2, Title1 = "111111" }).ExecuteCommand();
db.Insertable(new Test1 { Id = 9, Test0Id = 2, Title1 = "111111" }).ExecuteCommand();
var test1V = db.Queryable<Test0>().Select(x => new TestView
{
Id = x.Id.SelectAll(),
Test1V = SqlFunc.Subqueryable<Test1>().Where(w => w.Test0Id == x.Id).ToList(it => new Test1View()
{
Test0Id = it.Test0Id,
Title1 = it.Title1
})
}).ToList();
}
internal class Program
{
private static void Main(string[] args)
{
SugarIocServices.AddSqlSugar(new IocConfig()
{
ConnectionString = "",
DbType = IocDbType.PostgreSQL,
IsAutoCloseConnection = true,//自动释放
});
var db = DbScoped.SugarScope;
db.DbMaintenance.CreateDatabase();
//用来打印Sql方便你调式
db.Aop.OnLogExecuting = (sql, pars) =>
{
Console.WriteLine(sql + "\r\n" +
db.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value)));
Console.WriteLine();
};
db.Aop.OnError = (sql) =>
{
string ss = sql.Sql;
};
db.Aop.OnLogExecuting = (sql, p) =>
{
Console.WriteLine(sql);
};
db.Aop.OnLogExecuted = (sql, p) =>
{
Console.WriteLine(sql);
};
db.CodeFirst.InitTables(typeof(Test0), typeof(Test1));
Test(db);
}
热忱回答(7)
-
fate sta VIP0
2022/12/5ToList(w => new Test1View()
这个it换成w
0 回复 -
Mr、谢 VIP0
2022/12/5@fate sta:
0 回复 -
fate sta VIP0
2022/12/5我看一下,我这边SqlServer用例是通过了
0 回复 -
fate sta VIP0
2022/12/5SqlSugarCore
5.1.3.37已修复
0 回复 -
Mr、谢 VIP0
2022/12/5@fate sta:可以了
0 回复 -
fate sta VIP0
2022/12/6@Mr、谢:subquery.tolist 又修复了个BUG 当LIST记录为空会报错。升级到 38版本
0 回复 -
Mr、谢 VIP0
1个月前@fate sta:ToList支持关联查询吗?
0 回复