sqlkata / querybuilder

SQL query builder, written in c#, helps you build complex queries easily, supports SqlServer, MySql, PostgreSql, Oracle, Sqlite and Firebird
https://sqlkata.com
MIT License
3.09k stars 499 forks source link

how to use include #705

Open XxSu opened 8 months ago

XxSu commented 8 months ago

how to use include. I use code example :

var q = db.Query().From("SysUser");
//db.Statement
q.IncludeMany("UserRoles", db.Query("SysUserRole"),"Uid","Id");
var d1=  db.Get<SysUser>(q).ToList();

the table SysUserRole has one record ,but the d1 don't hava any list in the UserRoles propety but if I use db.Get(q).ToList(); the result is right

User00015 commented 7 months ago

The problem is that .Include is not supported using Get<T>. Its a huge gotcha.

The author expects you to use some way to convert dynamic back into an object from the Get(q) in your example, typically via serialized json.

won5572 commented 6 months ago

I use mapster for converting.


var test = pagedResult.Adapt<List<Test>>();