querybuilder icon indicating copy to clipboard operation
querybuilder copied to clipboard

how to use include

Open XxSu opened this issue 1 year ago • 2 comments

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

XxSu avatar Feb 11 '24 06:02 XxSu

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.

User00015 avatar Feb 21 '24 17:02 User00015

I use mapster for converting.

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

won5572 avatar Apr 05 '24 07:04 won5572