本文主要是介绍SqlSugar应用,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
实体自动映射到dto
db.Queryable<AbpUser>().Select<AbpUsersDto>(); //实体自动映射到dto
手动指定部分列的映射规则
[SugarTable("AbpUsers")]
public class AbpUser
{public int Id { get; set; }public string UserName { get; set; } //用户名public string Surname { get; set; } //昵称public string EmailAddress { get; set; }
}public class AbpUsersDto
{public int UserNameLength { get; set; }public int EmailAddressLength { get; set; }public string Surname { get; set; }
}db.Queryable<AbpUser>().Select(it => new AbpUsersDto()
{UserNameLength = it.UserName.Length, //手动指定映射规则EmailAddressLength = it.EmailAddress.Length 手动指定映射规则
},
true)//其余字段自动映射//产生的脚本如下
SELECT LEN([UserName]) AS [UserNameLength] , LEN([EmailAddress]) AS [EmailAddressLength] ,[Surname] AS [Surname] FROM [AbpUsers]
根据LeftJoin的别名自动映射
[SugarTable("InvOutBill")]
public class InvOutBill
{public string BillNo { get; set; }public int CreatedUserId { get; set; }
}public class InvOutBillDto
{public string BillNo { get; set; }public string CreateUserName { get; set; } //创建者账号:根据LeftJoin的别名自动映射
}db.Queryable<InvOutBill>()
.LeftJoin<AbpUsers>((i, Create)=>i.CreatedUserId == Create.Id)
Select<InvOutBillDto>()
这篇关于SqlSugar应用的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!