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

Join 语句

时间:2017-12-11 18:53:13      阅读:97      评论:0      收藏:0      [点我收藏+]

标签:pos   var   过程   pre   删除   extent   author   nbsp   return   

select * from books as A join (select * from Orders) as B on A.BookId = B.BookId  

select  A.BookId,Authorname,title,Address,Num  from books A right join (select  *  from Orders) as B on A.BookId = B.BookId 
存储过程 jon
exec sp_executesql NSELECT 
    [Extent1].[OrderId] AS [OrderId], 
    [Extent1].[Address] AS [Address], 
    [Extent1].[Num] AS [Num], 
    [Extent2].[BookId] AS [BookId], 
    [Extent2].[AuthorName] AS [AuthorName], 
    [Extent2].[Title] AS [Title]
    FROM  [dbo].[Orders] AS [Extent1]
    INNER JOIN [dbo].[books] AS [Extent2] ON [Extent1].[BookId] = [Extent2].[BookId]
    WHERE [Extent1].[BookId] = @p__linq__0,N@p__linq__0 int,@p__linq__0=1

 

 //使用join连接   //查询订单中的指定Bookid的数据  join  图书表中的指定bookid的数据
                var data = db.Order.Where(x => x.BookId == id).Join(db.Book, s => s.BookId, j => j.BookId, (s, j) => new
                {
                    Address = s.Address,
                    Num = s.Num,
                    OrderId = s.OrderId,
                    BookId = j.BookId,
                    AuthorName = j.AuthorName,
                    Title = j.Title
                });

                ViewBag.Data = data;
                return View();//根据图书id查找订单

 读取数据

 @foreach (var i in ViewBag.Data)
            {
            <tr>

                <td>@i.GetType().GetProperty("Title").GetValue(i, null)</td>
                <td>@i.GetType().GetProperty("AuthorName").GetValue(i, null)</td>
                <td>@i.GetType().GetProperty("Address").GetValue(i, null)</td>
                <td>@i.GetType().GetProperty("Num").GetValue(i, null)</td>
                <td>
                    <a onclick="del(this)">删除</a>
                </td>
            </tr>
            }

 

Join 语句

标签:pos   var   过程   pre   删除   extent   author   nbsp   return   

原文地址:http://www.cnblogs.com/enych/p/8024144.html

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