码迷,mamicode.com
首页 > 数据库 > 详细

Sql sugar的使用

时间:2020-06-05 13:06:14      阅读:93      评论:0      收藏:0      [点我收藏+]

标签:ring   user   rem   shu   lis   ati   app   ble   基本   

基本方法 http://www.codeisbug.com/Doc/8/1170

查看详情 一对多:

var result= _adminDbContext.Queryable<T_C_Base_PublishInformation, T_C_Base_PublishInfoLookor>(
                (t1, t2) => new object[] {
                    JoinType.Left, t1.Id == t2.PublishId
                })
               
                .Select((t1, t2) => new T_C_Base_PublishInformation
                {
                    Id = t1.Id,
                    Title = t1.Title,
                    PublishRange = t1.PublishRange,
                    IsUp = t1.IsUp,
                    IsEffective = t1.IsEffective,
                    PublishUser = t1.PublishUser,
                    PubulishTime = t1.PubulishTime,
                    Attachment = t1.Attachment,
                    Content = t1.Content,
                    Creator = t1.Creator,
                    CreateTime = t1.CreateTime
                })
                 .Mapper((it, cache) =>
                 {
                     var infos = cache.Get(list =>
                     {
                         var ids = list.Select(i => i.Id).ToList();
                         return _adminDbContext.Queryable<T_C_Base_PublishInformation, T_C_Base_PublishInfoLookor>((st, sc) => new object[] {
                                JoinType.Inner,st.Id==sc.PublishId})
                         .Select((st, sc) => new T_C_Base_PublishInfoLookor { PublishId = st.Id, CompanyName = sc.CompanyName }).ToList();
                     });
                     /*一对多*/
                     //创建人 
                     var CreateUser = _adminDbContext.Queryable<T_C_Base_PublishInfoLookor>().First(s => s.PublishId == it.Id);
                     //it.CompanyName = CreateUser?.CompanyName ?? "";
                     it.Lookor = string.Join(",", infos.Where(i => i.PublishId == it.Id).ToList().Select(q => q.CompanyName).ToArray());
                 })
                  .WhereIF(!string.IsNullOrEmpty(Id), t1 => t1.Id == Id);

 

Sql sugar的使用

标签:ring   user   rem   shu   lis   ati   app   ble   基本   

原文地址:https://www.cnblogs.com/gao109214/p/13048921.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!