Linq语法I

1、Linq查询:
var re = from o in db.Order  
         join d in db.OrderDetail  
         on o.Code equals d.OrderCode  
         join p in db.Product  
         on d.ProductID equals p.id  
         where o.Code == "20150326000096"  
         select new {  
            OrderCode = o.Code,  
            ProductName = p.Name,  
            SalePrice = p.SalePrice,  
            ProductQuantity = d.Quantity,  
            Amount = d.Amount  
         }; 

等价于:
 SELECT   
    [Extent1].[ProductID] AS [ProductID],   
    [Extent1].[OrderCode] AS [OrderCode],   
    [Extent2].[Name] AS [Name],   
    [Extent2].[SalePrice] AS [SalePrice],   
    [Extent1].[Quantity] AS [Quantity],   
    [Extent1].[Amount] AS [Amount]  
    FROM  [dbo].[OrderDetails] AS [Extent1]  
    INNER JOIN [dbo].[Products] AS [Extent2] ON [Extent1].[ProductID] = [Extent2].[id]  
    WHERE ([Extent1].[OrderCode] IS NOT NULL) AND (N'20150326000096' = [Extent1].[OrderCode])

2、

lambda:
re = db.OrderDetail.Where(d => d.OrderCode == "20150326000096").Select(d => new {  
                    OrderCode = d.Order.Code,  
                    ProductName = d.Product.Name,  
                    SalePrice = d.Product.SalePrice,  
                    ProductQuantity = d.Quantity,  
                    Amount = d.Amount                 
                });  

等价于:(N 在这里表示(nvarchar)Unicode)

3、

公用表达式:
with tmp as(
    select userid,score from gamescoreinfo gsi where score<1000
)
update gamescoreinfo set score=t.score+100
    from gamescoreinfo gsi
    inner join tmp t on gsi.userid=t.userid


方法一:
select p.ID,p.ProjectNO,p.ProjectName,p.ContractNumber,c.ContactStates from LbtProjectInfo p  join ContractRview c  on c.xmbh=p.ContractNumber where c.ContactStates='2'  and p.ProjectName not in(select d.ProjectName  from LabsFlow d);

-----------------
方法二:(效果更好)
with cr
as
(
select d.ProjectName  from LabsFlow d
)
select p.ID,p.ProjectNO,p.ProjectName,p.ContractNumber,c.ContactStates from LbtProjectInfo p 
inner  join ContractRview c  on c.xmbh=p.ContractNumber where c.ContactStates='2'  
and p.ProjectName not in(select  e.ProjectName  from cr e)


=================
临时表 TP
虚拟表pj
select * into TP from (select p.ID,p.ProjectNO,p.ProjectName,p.ContractNumber,c.ContactStates from LbtProjectInfo p 
inner  join ContractRview c  on c.xmbh=p.ContractNumber where c.ContactStates='2')pj


=========================
public static DataTable PageView(string tbname, string FieldKey, int PageCurrent, int PageSize, string FieldShow, string Where, string FieldOrder, ref int RecordCount)  
    {  
        SqlParameter[] parms = new SqlParameter[]   
        {   
            new SqlParameter("@tbname",SqlDbType.VarChar),   
            new SqlParameter("@FieldKey",SqlDbType.VarChar,1000),  
            new SqlParameter("@PageCurrent",SqlDbType.Int),  
            new SqlParameter("@PageSize",SqlDbType.Int),  
            new SqlParameter("@FieldShow",SqlDbType.VarChar,1000),  
            new SqlParameter("@Where",SqlDbType.VarChar,1000),  
            new SqlParameter("@FieldOrder",SqlDbType.VarChar,1000),  
            new SqlParameter("@PageCount",SqlDbType.Int),  
            new SqlParameter("@RecordCount",SqlDbType.Int),  
  
  
        };  
        parms[0].Value = tbname;  
        parms[1].Value = FieldKey;  
        parms[2].Value = PageCurrent;  
        parms[3].Value = PageSize;  
        parms[4].Value = FieldShow;  
        parms[5].Value = Where;  
        parms[6].Value = FieldOrder;  
        parms[7].Direction = ParameterDirection.Output;  
        parms[8].Direction = ParameterDirection.Output;  
  
  
        DataTable dt = new DataTable();  
        SQLHelper.FillDataTablePage("PageView", dt, parms);  
        RecordCount = Convert.ToInt32(parms[8].Value);  
        return dt;  
  
  
    }


 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值