xaml:
<grid>
<grid.columndefinitions>
<columndefinition width="2*"/>
<columndefinition width="8*"/>
</grid.columndefinitions>
<grid.rowdefinitions>
<rowdefinition />
<rowdefinition />
<rowdefinition />
</grid.rowdefinitions>
<listbox grid.column="1" margin="10" name="listbox1" />
<button content="linqtoentity" grid.column="0" margin="5" name="button1" click="button1_click" />
<listbox grid.column="1" grid.row="1" margin="10" name="listbox2" />
<button content="linqtosql" grid.column="0" grid.row="1" margin="5" name="button2" click="button2_click" />
<listbox grid.column="1" grid.row="2" margin="10" name="listbox3" />
<button content="lintoenclient" grid.column="0" grid.row="2" margin="5" name="button3" click="button3_click" />
</grid>
button1 linq to entity
using (var context = new adventureworks2008entities())
{
//var people = context.people.where(c => c.lastname == "king").orderby(d => d.firstname).select(r => new { r.firstname,r.lastname});
//var people = context.people.where(c => c.lastname == "king").orderby(c =>c.firstname).select(c => new { c.firstname, c.lastname });
var people = from per in context.people
//join emp in context.employees on per.businessentityid equals emp.businessentityid
where per.lastname == "king"
orderby per.firstname
select new { per.firstname, per.lastname};
foreach (var person in people)
{
listbox1.items.add(string.format("{0} \t \t {1} ", person.firstname, person.lastname));
}
}
button2 linq to entitysql
using (var context = new adventureworks2008entities())
{
var str = "select value p from adventureworks2008entities.people as p where p.lastname= @lastname order by p.firstname";
//var people = context.createquery<person>(str);
var people = new system.data.objects.objectquery<person>(str, context);
people.parameters.add(new system.data.objects.objectparameter("lastname", "king"));
foreach (var person in people)
{
listbox2.items.add(string.format("{0} \t \t{1}", person.firstname, person.lastname));
}
}
button3 linq to entityclient
var firstname = "";
var lastname = "";
using (entityconnection conn = new entityconnection("name=adventureworks2008entities"))
{
string str = "select p.firstname, p.lastname from adventureworks2008entities.people as p where p.lastname='king' order by p.firstname";
conn.open();
entitycommand cmd = conn.createcommand();
cmd.commandtext =str;
using (entitydatareader rdr = cmd.executereader(system.data.commandbehavior.sequentialaccess))
{
while (rdr.read())
{
firstname = rdr.getstring(0);
lastname = rdr.getstring(1);
listbox3.items.add(string.format("{0}\t \t{1}", firstname, lastname));
}
}
conn.close();
}
}
如对本文有疑问,
点击进行留言回复!!
相关文章:
-
-
C#实现猜数字游戏
本文实例为大家分享了c#实现猜数字游戏具体代码,供大家参考,具体内容如下给定一个0-100的随机数字猜其大小题目样式:电脑产生一个0到100之间的随机数字,并且...
[阅读全文]
-
-
C# 可空类型的具体使用
在项目中我们经常会遇到可为空类型,那么到底什么是可为空类型呢?下面我们将从4个方面为大家剖析。1、可空类型基础知识顾名思义,可空类型指的就是某个对象类型可以为空...
[阅读全文]
-
-
-
C#实现猜数字小游戏
本文实例为大家分享了c#实现猜数字小游戏的具体代码,供大家参考,具体内容如下效果如图:代码:using system;using system.collecti...
[阅读全文]
-
-
C#实现简单俄罗斯方块
最近在看《.net游戏编程入门经典 c#篇》 第一章介绍了如何制作俄罗斯方块,自己试了试按照书上的步骤,可算是完成了。于是写下这篇文章留作纪念。1.类的设计在充...
[阅读全文]
-
-
网友评论