随笔分类 -  Asp.net Linq

Linq技术
查询表达式与查询操作符
摘要://查询操作符public static void LambdaDemoDelegatePlus() { var result=Process.GetProcesses().where(pro=>pro.WorkingSet64>20*1024*1024) .OrderByDescending(pro>pro.WorkingSet64) .select(pro=>{id=pro.Id,Name=pro.ProcessName,Memory=pro.WorkingSet64}); ObjectDumper.Write(result,1); }//查询表达式public s 阅读全文

posted @ 2013-12-10 17:09 谭一丹 阅读(257) 评论(0) 推荐(0)

Lambda(2)
摘要:Lambda表达式是匿名方法的超集,处理匿名方法有的功能外,还有其他的功能:1.能够推测出参数的类型,无需显示声明2.支持语句块和表达式作为方法体Lambda表达式的书写方式:Lambda表达式有两种:语句Lambda和表达式Lambda例如:var re=>re+1 ---表达式Lambdavar re=>{return re+1;}---语句Lambda语句Lambda的操作符右边有一个{},其他的和表达式Lambda没什么区别 阅读全文

posted @ 2013-12-10 11:51 谭一丹 阅读(213) 评论(0) 推荐(0)

Linq中延迟查询和立即查询
摘要://立即查询 public static void NowExecute() { var results = new int[]{5,4,3,2,1,6,7,8,9,0 }; int i = 0; var res = (from re in results select ++i).ToList();//立即查询,此时,i=10,res={1,2,3,4,5,6,7,8,9,10} foreach (var p in res) { Console.WriteLine("{0},{1}",i,p); } }单步调试结果:执行F10从调试结果可以看出,ToList后变为立即查询, 阅读全文

posted @ 2013-12-10 11:32 谭一丹 阅读(374) 评论(0) 推荐(0)

Linq--扩展方法
摘要:如果现在有一个这样的需求,求筛选出来的大于20MB的进程的和,常用的方法是写一个静态方法传进去一个ProcessData列表比如:public static Int64 TotalMemory( IEnumerable process) { Int64 result = 0; foreach(var pro in process) { result +=pro.Memory; } return result; }如果现在还有一个需求:将筛选出来的结果用MB表示比如:Public static Int64 ByteToMegaByte(Int64 bytes){ return bytes/102 阅读全文

posted @ 2013-12-09 15:27 谭一丹 阅读(204) 评论(0) 推荐(0)

Lambda
摘要:using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace LinqDemo{ public class ProcessData { public int id { get; set; } public string Name { get; set; } public Int64 Memory { get; set; } }}using System;using System.Collections.Generic;using System.Linq;using Syst 阅读全文

posted @ 2013-12-07 17:42 谭一丹 阅读(363) 评论(0) 推荐(0)

dotNet中初始化器的使用
摘要:dotNet中初始化器的使用2013年12月7日13:27有两类初始化器:对象初始化器和集合初始化器比如现在有一个User类:Public class User{ public int id{get;set;} public string Name{get;set;} public int Age{get;set;}}对象初始化器:Var user=new User{id=1,Name="danche",Age=23}"传统"的方法:User user=new User();user.id=1;user.Name="danche";u 阅读全文

posted @ 2013-12-07 15:12 谭一丹 阅读(194) 评论(0) 推荐(0)

Linq To Xml
摘要:using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace LinqDemo{ public class Book { public string Title; public string Author; public DateTime Year; public Book(string author, string title, DateTime year) { Title = title; Author = author; Year = year; } }}using 阅读全文

posted @ 2013-12-04 16:59 谭一丹 阅读(751) 评论(0) 推荐(0)

Linq to Entities
摘要:首先要添加一个ADO.NET实体数据模型添加一个Entities 对象,其用法和linqtosql类似例如: StudentInfoEntities2 entity = new StudentInfoEntities2(); protected void Page_Load(object sender, EventArgs e) { if(!Page.IsPostBack) { studentIfo(); } } ... 阅读全文

posted @ 2013-07-04 10:14 谭一丹 阅读(158) 评论(0) 推荐(0)

Linq to sql
摘要:注意:如果窗体程序使用内置数据库你在VS中看的数据库是项目中的数据库,你编译时用到的的数据库是debug下的数据库文件,查看你项目中数据库的“复制到输出目录”属性,肯定是始终复制,意思就是每次拟推迟编译的时候会把你项目中的数据库覆盖你debug下的数据库,所以你每次编译后虽然在debug下的数据库成功更改数据了,但是之后就会被外面的数据库覆盖。解决办法:在程序的main函数中添加如下代码:string dataDir = AppDomain.CurrentDomain.BaseDirectory;if(dataDir.EndsWith(@"\bin\Release\")|| 阅读全文

posted @ 2013-07-04 10:05 谭一丹 阅读(146) 评论(0) 推荐(0)

导航