码迷,mamicode.com
首页 > 其他好文 > 详细

Linq语法学习

时间:2016-08-12 11:22:53      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:

  • 关键词:

select

from

where

in

into

join

on

equals

orderby

descending

DefaultIfEmpty()

thenby

 

submitChanges();

DeleteAllOnSubmit()

InsertAllOnSubmit() 

 

  • 常用1
/// <summary>报销单是否被增值税引用
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool IsRefWithholding(string id)
        {
            var isRefWithholding = (from wh in _dataContext.Withholdings
                                    join clp in _dataContext.ClaimSheetBaseInProjects on wh.ClaimSheetBaseInProjectId equals clp.Id
                                    join cl in _dataContext.ClaimSheetBases on clp.bxdId equals cl.Id
                                    where cl.Id == id
                                    select wh).Count() > 0;
            return isRefWithholding;
        }
  • 修改用例:
public void UpdateClaimSheetBaseForFrozen(ClaimSheetBaseDto item)
        {
            _dataContext.CommandTimeout = 180;
            if (item != null)
            {
                var claimSheetBase = _dataContext.ClaimSheetBases.Single(a => a.Id.Equals(item.Id));
                claimSheetBase.IsFrozen = item.IsFrozen;
                claimSheetBase.FrozenCode = item.FrozenCode;
                _dataContext.SubmitChanges();
            }
        }
  •   删除用例:
public void DelectProjectPay(ClaimSheetBaseDto item)
        {
            if (item.IsMulPay.Equals(true))
            {
               
                var projectPay = _dataContext.ProjectPay.Where(o => o.ClaimSheetBaseId == item.Id);
                if (item.PaymentByReverseDto != null)
                {
                    _dataContext.ProjectPay.DeleteAllOnSubmit(projectPay);
                }                
            }
        }

 增加用例:

/// <summary>添加附件
        /// 先删除后增加
        /// </summary>
        /// <param name="claimSheetBaseId"></param>
        /// <param name="?"></param>
        /// <returns></returns>
        public bool AddAttachmentWB(ClaimSheetBaseDto item)
        {
            if (item.AttachmentDtos != null)
            {
                var attachments = _dataContext.AttachmentWB.Where(a => a.ClaimSheetBaseId.Equals(item.Id));
                if (attachments != null && attachments.Count() > 0)
                {
                    _dataContext.AttachmentWB.DeleteAllOnSubmit(attachments);
                }
                var attachmentDtos = new List<AttachmentWB>();
                foreach (var attachment in item.AttachmentDtos)
                {
                    attachmentDtos.Add(RePackAttachment(attachment));
                }

                _dataContext.AttachmentWB.InsertAllOnSubmit(attachmentDtos);
            }
            _dataContext.SubmitChanges();
            return true;

        }

 

Linq语法学习

标签:

原文地址:http://www.cnblogs.com/jacketlin/p/5752275.html

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