#TIL 10 - Add User Define Function to TypeORM entity
![blog_hero_#TIL 10 - Add User Define Function to TypeORM entity](/_next/image?url=%2Fstatic%2Ftil.jpeg&w=2048&q=75)
This is a workaround that I found from the TypeORM issue. Simply, the solution would implement as below
Step 1: Add custom field to the class entity
// add to User.ts entity
@Column('int', { insert: false, readonly: true })
public qty: number;
Step 2: query the custom field with query builder
// need to mapping with the convention: table + _ + UDF column (user_qty)
.addSelect('dbo.udfFindTotalQty(user.id)', 'user_qty')
...
.printSql()
.getManyAndCount();