Sql sugar的使用
Posted gao109214
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Sql sugar的使用相关的知识,希望对你有一定的参考价值。
基本方法 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的使用的主要内容,如果未能解决你的问题,请参考以下文章