ASP.NET EF 使用LinqPad 快速学习Linq
使用LinqPad这个工具可以很快学习并掌握linq[Language Integrated Query]
linqPad官方下载地址:http://www.linqpad.net/
linqPad4百度云下载(for .NET Framework4.0/4.5):链接:http://pan.baidu.com/s/1gflmRDp 密码:3n3f
linqPad5百度云下载(for .NET Framework 4.6):链接:http://pan.baidu.com/s/1dE5Z0VB 密码:qpgc
LINQPad is not just for LINQ queries, but any C#/F#/VB expression, statement block or program. Put an end to those hundreds of Visual Studio Console projects cluttering your source folder and join the revolution of LINQPad scripters and incremental developers.
Reference your own assemblies and NuGet packages. Prototype your ideas in LINQPad and then paste working code into Visual Studio. Or call your scripts directly from the command-line.
Experience LINQPad’s rich output formatting, optional debugger and autocompletion, and the magic of dynamic development and instant feedback!
引用你自己的程序集和 NuGet 程序包。原型的你的想法在 LINQPad,然后粘贴工作代码到 Visual Studio。或直接从命令行调用您的脚本。
体验 LINQPad 的丰富的输出格式、 可选的调试器和自动完成和神奇的动态发展和即时反馈 !

先在数据库创建一个数据库MyFirstEF 和CustomerInfo和OrderInfo两张表
create database MyFirstEF
on primary
(
name='MyFirstEF.mdf',
--修改为自己电脑上SQL DB路径
filename='E:\ProgramMSSQLServerDB\MyFirstEF.mdf',
size=5mb,
maxsize=100mb,
filegrowth=10%
)
log on
(
name='MyFirstEF_log.ldf',
--修改为自己电脑上SQL DB路径
filename='E:\ProgramMSSQLServerDB\MyFirstEF_log.ldf',
size=2mb,
maxsize=100mb,
filegrowth=5mb
)
go use MyFirstEF
go create table CustomerInfo
(
id int identity(1,1) primary key,
customerName nvarchar(100) not null,
customerDate datetime
)
go create table OrderInfo
(
id int identity(1,1) primary key,
orderName nvarchar(100),
customerId int
)
go insert into CustomerInfo
select 'aa',GETDATE() union all
select 'bb',GETDATE() union all
select 'cc',GETDATE() union all
select 'dd',GETDATE()
go insert into OrderInfo
select 'bike1',2 union all
select 'bike2',2 union all
select 'car1',3 union all
select 'car2',3 union all
select 'chezi1',4 union all
select 'chezi2',4 union all
select 'test1',5 union all
select 'test2',5
go select * from CustomerInfo
go select * from OrderInfo
go
--create SQL
安装完毕linqPad之后,打开软件 --Add Connection-->Build data context automatically(Default(LINQ to SQL))


我们在linqPad的query标签里把Language 选择为c# Expression ,把Connection 选择数据MyFirstEF

1:Linq left join(left join 是Left outer join 简写)
在面板中输入Linq,点击运行或者直接按F5【注意CustomerInfo/OrderInfo及字段 都需要按照EF中的格式写(不能按照数据库格式)】
from c in CustomerInfo
join o in OrderInfo
on c.Id equals o.CustomerId
into MyLeftJoin
from tt in MyLeftJoin.DefaultIfEmpty()
select new
{
cname=c.CustomerName,
//这里主要第二个集合有可能为空。需要判断
//oname=tt==null?"":tt.OrderName
oname=tt.OrderName
}
对应SQL为:
SELECT [t0].[customerName] AS [cname], [t1].[orderName] AS [oname]
FROM [CustomerInfo] AS [t0]
LEFT OUTER JOIN [OrderInfo] AS [t1] ON ([t0].[id]) = [t1].[customerId]
对应lambda表达式为:
CustomerInfo
.GroupJoin (
OrderInfo,
c => (Int32?)(c.Id),
o => o.CustomerId,
(c, MyLeftJoin) =>
new
{
c = c,
MyLeftJoin = MyLeftJoin
}
)
.SelectMany (
temp0 => temp0.MyLeftJoin.DefaultIfEmpty (),
(temp0, tt) =>
new
{
cname = temp0.c.CustomerName,
oname = tt.OrderName
}
)

2:Linq right join(right join 是Right outer join 简写)[最后生成SQL还是left join]
在面板中输入Linq,点击运行或者直接按F5
from o in OrderInfo
join c in CustomerInfo
on o.CustomerId equals c.Id
into MyRightJoin
from tt in MyRightJoin.DefaultIfEmpty()
select new
{
//这里集合有可能为空。需要判断
//cname=tt==null?"":tt.CustomerName,
cname=tt.CustomerName,
oname=o.OrderName
}
对应SQL为:
SELECT [t1].[customerName] AS [cname], [t0].[orderName] AS [oname]
FROM [OrderInfo] AS [t0]
LEFT OUTER JOIN [CustomerInfo] AS [t1] ON [t0].[customerId] = ([t1].[id])
对应lambda表达式为:
OrderInfo
.GroupJoin (
CustomerInfo,
o => o.CustomerId,
c => (Int32?)(c.Id),
(o, MyRightJoin) =>
new
{
o = o,
MyRightJoin = MyRightJoin
}
)
.SelectMany (
temp0 => temp0.MyRightJoin.DefaultIfEmpty (),
(temp0, tt) =>
new
{
cname = tt.CustomerName,
oname = temp0.o.OrderName
}
)

3:Linq inner join
在面板中输入Linq,点击运行或者直接按F5
from c in CustomerInfo
join o in OrderInfo
on c.Id equals o.CustomerId
select new
{
cname=c.CustomerName,
oname=o.OrderName
}
对应SQL为:
SELECT [t0].[customerName] AS [cname], [t1].[orderName] AS [oname]
FROM [CustomerInfo] AS [t0]
INNER JOIN [OrderInfo] AS [t1] ON ([t0].[id]) = [t1].[customerId]
对应lambda表达式为:
CustomerInfo
.Join (
OrderInfo,
c => (Int32?)(c.Id),
o => o.CustomerId,
(c, o) =>
new
{
cname = c.CustomerName,
oname = o.OrderName
}
)

暂时就到这里,其他的参考官方文档。
参考链接:
ASP.NET MVC EF直接更新数据(不需查询):http://www.cnblogs.com/Dr-Hao/p/5255630.html
ASP.NET EF(LINQ/Lambda查询):http://www.cnblogs.com/Dr-Hao/p/5356928.html
ASP.NET EF 使用LinqPad 快速学习Linq的更多相关文章
- js_html_input中autocomplete="off"在chrom中失效的解决办法 使用JS模拟锚点跳转 js如何获取url参数 C#模拟httpwebrequest请求_向服务器模拟cookie发送 实习期学到的技术(一) LinqPad的变量比较功能 ASP.NET EF 使用LinqPad 快速学习Linq
js_html_input中autocomplete="off"在chrom中失效的解决办法 分享网上的2种办法: 1-可以在不需要默认填写的input框中设置 autocompl ...
- linqPad快速学习LINQ(含视频)
在这里我向大家推荐的一个具是LinqPad有了这个工具并熟练使用就可以很快学习并掌握linq 安装步骤: 使用LINQPad可以很方便的调试linq以及lambda表达式.其中自带了linq以及F#简 ...
- LinqPad工具:帮你快速学习Linq
LinqPad工具:帮你快速学习Linq 参考: http://www.cnblogs.com/li-peng/p/3441729.html ★:linqPad下载地址:http://www.linq ...
- 用linqPad帮助你快速学习LINQ
在这里我向大家推荐的一个具是LinqPad有了这个工具并熟练使用就可以很快学习并掌握linq linqPad下载地址:http://www.linqpad.net/ 它也自带了很多例子方便大家查询,l ...
- linqPad帮助你快速学习LINQ
linqPad http://www.cnblogs.com/li-peng/p/3441729.html http://www.linqpad.net/ Linqer http://www.sqlt ...
- ASP.NET EF(LINQ/Lambda查询)
EF(EntityFrameWork) ORM(对象关系映射框架/数据持久化框架),根据实体对象操作数据表中数据的一种面向对象的操作框架,底层也是调用ADO.NET ASP.NET MVC 项目会自动 ...
- ASP.NET快速学习方案(.NET菜鸟的成长之路)
想要快速学习ASP.NET网站开发的朋友可以按照下面这个学习安排进度走.可以让你快速入门asp.net网站开发!但也局限于一般的文章类网站!如果想学习更多的技术可以跟着我的博客更新走!我也是一名.NE ...
- 学习LINQ,发现一个好的工具。LINQPad!!
今日学习LINQ,发现一个好的工具.LINQPad!! 此工具的好处在于,不需要在程序内执行,直接只用工具测试.然后代码通过即可,速度快,简洁方便. 可以生成其LINQ查询对应的lambda和SQL语 ...
- 使用ASP.NET MVC+Entity Framework快速搭建系统
详细资料: http://www.cnblogs.com/dingfangbo/p/5771741.html 学习 ASP.NET MVC 也有一段时间了,打算弄个小程序练练手,做为学习过程中的记录和 ...
随机推荐
- openssl 编程
背景: 生成私钥.公钥 --> 生成AES-key seed[32], iv[16] --> 公钥加密ASE-key, IV,传给Server --> Server用私钥解密,得到A ...
- SQL Inserted和deleted详解
create trigger updateDeleteTime on user for update as begin update user set UpdateTime=(getdate()) f ...
- BZOJ4921 互质序列
即求删掉一个子序列的gcd之和.注意到前后缀gcd的变化次数都是log级的,于是暴力枚举前缀gcd和后缀gcd即可. #include<iostream> #include<cstd ...
- 洛谷 P1231 教辅的组成(网络最大流+拆点加源加汇)
题目背景 滚粗了的HansBug在收拾旧语文书,然而他发现了什么奇妙的东西. 题目描述 蒟蒻HansBug在一本语文书里面发现了一本答案,然而他却明明记得这书应该还包含一份练习题.然而出现在他眼前的书 ...
- 【POJ2891】Strange Way to Express Integers(拓展CRT)
[POJ2891]Strange Way to Express Integers(拓展CRT) 题面 Vjudge 板子题. 题解 拓展\(CRT\)模板题. #include<iostream ...
- 洛谷 P3539 [POI2012]ROZ-Fibonacci Representation 解题报告
P3539 [POI2012]ROZ-Fibonacci Representation 题意:给一个数,问最少可以用几个斐波那契数加加减减凑出来 多组数据10 数据范围1e17 第一次瞬间yy出做法, ...
- CentOS7.4 删除virbr0虚拟网卡
在CentOS 7的安装过程中如果有选择相关虚拟化的的服务安装系统后,启动网卡时会发现有一个以网桥连接的私网地址的virbr0网卡,这个是因为在虚拟化中有使用到libvirtd服务生成的,如果不需要可 ...
- SVN跨服务器自动更新--实现文件分发
目标:SVN版本库提交,服务器中的工作拷贝能自动update. 实现方法:subversion, curl,php脚本实现,并且入mysql库来进行管理.改hosts文件来进行访问!提交触发钩子脚本时 ...
- Codeforces Global Round 2 题解
Codeforces Global Round 2 题目链接:https://codeforces.com/contest/1119 A. Ilya and a Colorful Walk 题意: 给 ...
- 多线程中join方法的含义
1.作用:调用这个方法的时候,主进程会在这里停住,等待该线程进行完毕再继续往下执行. 如:不使用join的情况: <?php class Join extends Thread { public ...