sqlkata/querybuilder

how to use include

XxSu opened this issue · 2 comments

XxSu commented

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

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.

I use mapster for converting.

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