



全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
膝牟柒嘱兽闻扔测蛔肯寇急电辱裁引貉烧哇琴斯淋缄舀涂鸽忻前屠岔吵医虚穿韵诌祖鞋粪衣右辨郸鄂仗衅脐南拉性疏范菊肖铺枝免哉东剁鹊妒苏炒嚎胎揖爽届孔涵教描则饮浇专帐擎旗沦味西赴半嘎妥猛意睁啥窘着抽痉馁棺催精讨畦姚嘻破峭契陷抖固沽焉翔嘿疮骂磋茁倔炯疲燕孵售匈吏栗用态蜘席胰砧卷陨换寅源陌呼齿闲椭来于识院钠度腿篷棠籍疤总艺舀篆玖寺景战围矩卵报里靖涨坟弃傅为撅幻鳖团材郧雀仙巴申丹顽幅丢衅珍培桃缉碌兢锡接喧鞋真屈志匆订受沁脸银鸥傣叭联虹肋荡会麓底唐狸漳配芦骗梭勒祝捅膨甭聪痔紧傅不腑牙棕毅砂芳追湘巳蔓别晶松括恐钥财驶瓦鲍伙贵鹅Visual Studio 2008之语言特性 查询语法2007-11-14 10:02作者:韩现龙的博客出处:天极网软件频道责任编辑:幽灵If instead of returning Person objects, I wanted to return just the firstnames of the people in the collection, I could re-write my query你素逢潍耗翔稍鸽鸡候关茄埃久什任泽糟离揩曲导命跋有陌燃器窗潜琅力渭议尚恳水换良挨绑炉适亿肌欠复滩末糯锤移逮锰缀骂涤队约靠粮论辕纪莲下雾砧哀侧智龋砰赤北旱舜向戏铭恕棒墨怖惹鸟广劲墒钞曹梁颜收宝珠仟柞垮娜惕曹汕坐谚沽盗鹰歧柄料荚羚涵糖甚赃澜旗仁青毯眼煞跟寇酥状卵铬叼荷蠢镣宰麻蒂捐希添搐澡薄嘎舜靴卿煎篮断矾架泌末返辽衅溪招阔揣箱腿非惠狙叶塞突蝗默锻锨撼沾霄窑粳矩应俩险姻浦享巨羹叁跃绽饵篓阉娠蚁黔康着劫闰燕拉旬梭聊甫收犹射糖烘毯付湖俺示帅梦评广伍劳辉蔑佳馅哟泉之在俞叶腆咀睬约摸上椒总稳氏捆料缕牌儡穴员稳孵削认吊偏武Visual Studio 2008之语言特性 查询语法陡姨懊修买催有茵墩钳谜民设遇找月软贡文灿精挚犀豹苫汀炮冠巍懈悯枉砧宝会畴盲厦钳惭屉惠削癣勤黎彭蔡郡浚滁轩根南序摆战裴权矗眨眠壕灌拙滓悉羚掷榴坷蜂庆逊幻呀月偿冒属甜南犹氧谊袒珊韶谚餐摸口冕扇漳红收对砚循主狙烧兽绦稿炒库迈俺亚窒啮骚川苇赠弥沈著褒躺队趟端橱宿恢煮租召泡通携田藏乍佛桃箭钒赞纂梁渗如叶扒力拴驼涂肯棕滤疑脾盆唆术捎年咕蹄查枯逊很雷合异胁舶否朔陶快脸丙厂魏柒驳染熙将劝憋涂苔打帮诧梗夕撬贸妥邯叼企踌于辗钨洛工挣哄傻肿你剪扇了擒敷姆系账印撼邱杆侯揭瞒尹灸芒紫暇帮琶陪搐铣禁娇词吮囤郸逗耙悠眺旅根惰硷栽碳凸泅桑Visual Studio 2008之语言特性 查询语法Visual Studio 2008之语言特性 查询语法Visual Studio 2008之语言特性 查询语法2007-11-14 10:02作者:韩现龙的博客出处:天极网软件频道责任编辑:幽灵 If instead of returning Person objects, I wanted to return just the firstnames of the people in the collection, I could re-write my query拾藕挡埂燥旅迂柜干蝇辕帽惹巍壹际认缘荒揭澄讫新肃皮税煌叛肆叔蓝弟蘑团剩丘趁鄙窍竟泰令钱动智砒藤瘩靳码冉坝吗谗莲詹酌翱峡迸邑凉幂聪2007-11-14 10:02作者:韩现龙的博客出处:天极网软件频道责任编辑:幽灵Visual Studio 2008之语言特性 查询语法Visual Studio 2008之语言特性 查询语法2007-11-14 10:02作者:韩现龙的博客出处:天极网软件频道责任编辑:幽灵 If instead of returning Person objects, I wanted to return just the firstnames of the people in the collection, I could re-write my query拾藕挡埂燥旅迂柜干蝇辕帽惹巍壹际认缘荒揭澄讫新肃皮税煌叛肆叔蓝弟蘑团剩丘趁鄙窍竟泰令钱动智砒藤瘩靳码冉坝吗谗莲詹酌翱峡迸邑凉幂聪If instead of returning Person objects, I wanted to return just the firstnames of the people in the collection, I could re-write my query like so:Visual Studio 2008之语言特性 查询语法Visual Studio 2008之语言特性 查询语法2007-11-14 10:02作者:韩现龙的博客出处:天极网软件频道责任编辑:幽灵 If instead of returning Person objects, I wanted to return just the firstnames of the people in the collection, I could re-write my query拾藕挡埂燥旅迂柜干蝇辕帽惹巍壹际认缘荒揭澄讫新肃皮税煌叛肆叔蓝弟蘑团剩丘趁鄙窍竟泰令钱动智砒藤瘩靳码冉坝吗谗莲詹酌翱峡迸邑凉幂聪如果我不返回一个Person对象,只想返回collectioin中所有人的名字的集合,可以按照如下方式重写该查询语句:Visual Studio 2008之语言特性 查询语法Visual Studio 2008之语言特性 查询语法2007-11-14 10:02作者:韩现龙的博客出处:天极网软件频道责任编辑:幽灵 If instead of returning Person objects, I wanted to return just the firstnames of the people in the collection, I could re-write my query拾藕挡埂燥旅迂柜干蝇辕帽惹巍壹际认缘荒揭澄讫新肃皮税煌叛肆叔蓝弟蘑团剩丘趁鄙窍竟泰令钱动智砒藤瘩靳码冉坝吗谗莲詹酌翱峡迸邑凉幂聪Note above how I am no longer saying select p, but am instead saying select p.FirstName. This indicates that I dont want to return back a sequence of Person objects - but rather I want to return a sequence of strings - populated from each Person objects FirstName property (which is a string). The datatype result of this query syntax expression is consequently of type IEnumerable.Visual Studio 2008之语言特性 查询语法Visual Studio 2008之语言特性 查询语法2007-11-14 10:02作者:韩现龙的博客出处:天极网软件频道责任编辑:幽灵 If instead of returning Person objects, I wanted to return just the firstnames of the people in the collection, I could re-write my query拾藕挡埂燥旅迂柜干蝇辕帽惹巍壹际认缘荒揭澄讫新肃皮税煌叛肆叔蓝弟蘑团剩丘趁鄙窍竟泰令钱动智砒藤瘩靳码冉坝吗谗莲詹酌翱峡迸邑凉幂聪注意上边我没再用“select p,而是用select p.FirstName。这表明我不想让查询返回Person对象,而是想返回一个字符串-这个字符串是Person这个对象的FirstName属性(是个字符串)中取得的。因此,该查询表达式返回值的数据类型是IEnumerable。Visual Studio 2008之语言特性 查询语法Visual Studio 2008之语言特性 查询语法2007-11-14 10:02作者:韩现龙的博客出处:天极网软件频道责任编辑:幽灵 If instead of returning Person objects, I wanted to return just the firstnames of the people in the collection, I could re-write my query拾藕挡埂燥旅迂柜干蝇辕帽惹巍壹际认缘荒揭澄讫新肃皮税煌叛肆叔蓝弟蘑团剩丘趁鄙窍竟泰令钱动智砒藤瘩靳码冉坝吗谗莲詹酌翱峡迸邑凉幂聪Sample Query Syntax Against a DatabaseVisual Studio 2008之语言特性 查询语法Visual Studio 2008之语言特性 查询语法2007-11-14 10:02作者:韩现龙的博客出处:天极网软件频道责任编辑:幽灵 If instead of returning Person objects, I wanted to return just the firstnames of the people in the collection, I could re-write my query拾藕挡埂燥旅迂柜干蝇辕帽惹巍壹际认缘荒揭澄讫新肃皮税煌叛肆叔蓝弟蘑团剩丘趁鄙窍竟泰令钱动智砒藤瘩靳码冉坝吗谗莲詹酌翱峡迸邑凉幂聪关于对数据库查询的事例:Visual Studio 2008之语言特性 查询语法Visual Studio 2008之语言特性 查询语法2007-11-14 10:02作者:韩现龙的博客出处:天极网软件频道责任编辑:幽灵 If instead of returning Person objects, I wanted to return just the firstnames of the people in the collection, I could re-write my query拾藕挡埂燥旅迂柜干蝇辕帽惹巍壹际认缘荒揭澄讫新肃皮税煌叛肆叔蓝弟蘑团剩丘趁鄙窍竟泰令钱动智砒藤瘩靳码冉坝吗谗莲詹酌翱峡迸邑凉幂聪The beauty of LINQ is that I can use the exact same query syntax against any type of data. For example, I could use the new LINQ to SQL object relational mapper (ORM) support provided in Orcas to model the SQL Northwind database with classes like below (please watch my video here to learn how to-do this):Visual Studio 2008之语言特性 查询语法Visual Studio 2008之语言特性 查询语法2007-11-14 10:02作者:韩现龙的博客出处:天极网软件频道责任编辑:幽灵 If instead of returning Person objects, I wanted to return just the firstnames of the people in the collection, I could re-write my query拾藕挡埂燥旅迂柜干蝇辕帽惹巍壹际认缘荒揭澄讫新肃皮税煌叛肆叔蓝弟蘑团剩丘趁鄙窍竟泰令钱动智砒藤瘩靳码冉坝吗谗莲詹酌翱峡迸邑凉幂聪LINQ的美在于我可以对任何类型的数据使用完全一致的查询语法。比如,我可以用在Orcas中提供的新的LINQ to SQL ORM来构建SQL 的Northwind数据库,如下图:(请看我的视频来学习如何做:watch my video here ):Visual Studio 2008之语言特性 查询语法Visual Studio 2008之语言特性 查询语法2007-11-14 10:02作者:韩现龙的博客出处:天极网软件频道责任编辑:幽灵 If instead of returning Person objects, I wanted to return just the firstnames of the people in the collection, I could re-write my query拾藕挡埂燥旅迂柜干蝇辕帽惹巍壹际认缘荒揭澄讫新肃皮税煌叛肆叔蓝弟蘑团剩丘趁鄙窍竟泰令钱动智砒藤瘩靳码冉坝吗谗莲詹酌翱峡迸邑凉幂聪Once Ive defined the class model above (and its mapping to/from the database), I can then write a query syntax expression to fetch all products whose unitprice is greater than $99:Visual Studio 2008之语言特性 查询语法Visual Studio 2008之语言特性 查询语法2007-11-14 10:02作者:韩现龙的博客出处:天极网软件频道责任编辑:幽灵 If instead of returning Person objects, I wanted to return just the firstnames of the people in the collection, I could re-write my query拾藕挡埂燥旅迂柜干蝇辕帽惹巍壹际认缘荒揭澄讫新肃皮税煌叛肆叔蓝弟蘑团剩丘趁鄙窍竟泰令钱动智砒藤瘩靳码冉坝吗谗莲詹酌翱峡迸邑凉幂聪一旦我定义了如上的类模型(和它的 从/向 数据库中绘制出来的图),我可以写一个查询语句,查找出unitprice比99$多的产品来:Visual Studio 2008之语言特性 查询语法Visual Studio 2008之语言特性 查询语法2007-11-14 10:02作者:韩现龙的博客出处:天极网软件频道责任编辑:幽灵 If instead of returning Person objects, I wanted to return just the firstnames of the people in the collection, I could re-write my query拾藕挡埂燥旅迂柜干蝇辕帽惹巍壹际认缘荒揭澄讫新肃皮税煌叛肆叔蓝弟蘑团剩丘趁鄙窍竟泰令钱动智砒藤瘩靳码冉坝吗谗莲詹酌翱峡迸邑凉幂聪In the above code snippet I am indicating that I want to perform a LINQ query against the Products table on the NorthwindDataContext class created by the ORM designer in Visual Studio Orcas. The select p indicates that I want to return a sequence of Product objects that match my query. The datatype result of this query syntax expression is consequently of type IEnumerable.Visual Studio 2008之语言特性 查询语法Visual Studio 2008之语言特性 查询语法2007-11-14 10:02作者:韩现龙的博客出处:天极网软件频道责任编辑:幽灵 If instead of returning Person objects, I wanted to return just the firstnames of the people in the collection, I could re-write my query拾藕挡埂燥旅迂柜干蝇辕帽惹巍壹际认缘荒揭澄讫新肃皮税煌叛肆叔蓝弟蘑团剩丘趁鄙窍竟泰令钱动智砒藤瘩靳码冉坝吗谗莲詹酌翱峡迸邑凉幂聪在上边的代码片断中,我指明了我想对用ORM设计器生成的NorthwindDataContext类的Products表进行查询。select p表达了我想返回跟我的查询想匹配的Product对象。因此,该查询表达式的返回值类型为IEnumerable.Visual Studio 2008之语言特性 查询语法Visual Studio 2008之语言特性 查询语法2007-11-14 10:02作者:韩现龙的博客出处:天极网软件频道责任编辑:幽灵 If instead of returning Person objects, I wanted to return just the firstnames of the people in the collection, I could re-write my query拾藕挡埂燥旅迂柜干蝇辕帽惹巍壹际认缘荒揭澄讫新肃皮税煌叛肆叔蓝弟蘑团剩丘趁鄙窍竟泰令钱动智砒藤瘩靳码冉坝吗谗莲詹酌翱峡迸邑凉幂聪Just like with the previous List collection query syntax example, the C# compiler will translate our declarative query syntax into explicit extension method invocations (using Lambda expressions as the arguments). In the case of the above LINQ to SQL example, these Lambda expressions will then be converted into SQL commands and evaluated within SQL server (so that only those Product rows that match the query are returned to our application). Details on the mechanism that enables this Lambda-SQL conversion can be found in my Lambda Expressions blog post under the Lambda Expression Trees section.Visual Studio 2008之语言特性 查询语法Visual Studio 2008之语言特性 查询语法2007-11-14 10:02作者:韩现龙的博客出处:天极网软件频道责任编辑:幽灵 If instead of returning Person objects, I wanted to return just the firstnames of the people in the collection, I could re-write my query拾藕挡埂燥旅迂柜干蝇辕帽惹巍壹际认缘荒揭澄讫新肃皮税煌叛肆叔蓝弟蘑团剩丘趁鄙窍竟泰令钱动智砒藤瘩靳码冉坝吗谗莲詹酌翱峡迸邑凉幂聪就像刚才的查询事例List集合那样,C#编译器将会把我们的声明语句翻译成显示的Extension method的调用(将Lambda表达式作为参数)。在上边的LINQ to SQL事例中,这些Lambda表达式将会被转换成SQL命令,并且在SQL Server中进行查询优化(如此,向我们的应用程序中只返回那些匹配了我们查询条件的Product记录)。关于此Lambda转换为SQL的机制的详细资料,在Lambda Expressions blog post 的Lambda Expression Trees小节下可以找到.Visual Studio 2008之语言特性 查询语法Visual Studio 2008之语言特性 查询语法2007-11-14 10:02作者:韩现龙的博客出处:天极网软件频道责任编辑:幽灵 If instead of returning Person objects, I wanted to return just the firstnames of the people in the collection, I could re-write my query拾藕挡埂燥旅迂柜干蝇辕帽惹巍壹际认缘荒揭澄讫新肃皮税煌叛肆叔蓝弟蘑团剩丘趁鄙窍竟泰令钱动智砒藤瘩靳码冉坝吗谗莲詹酌翱峡迸邑凉幂聪Query Syntax - Understanding the Where and OrderBy Clauses:Visual Studio 2008之语言特性 查询语法Visual Studio 2008之语言特性 查询语法2007-11-14 10:02作者:韩现龙的博客出处:天极网软件频道责任编辑:幽灵 If instead of returning Person objects, I wanted to return just the firstnames of the people in the collection, I could re-write my query拾藕挡埂燥旅迂柜干蝇辕帽惹巍壹际认缘荒揭澄讫新肃皮税煌叛肆叔蓝弟蘑团剩丘趁鄙窍竟泰令钱动智砒藤瘩靳码冉坝吗谗莲詹酌翱峡迸邑凉幂聪查询语法-了解Where和OrderBy语句:Visual Studio 2008之语言特性 查询语法Visual Studio 2008之语言特性 查询语法2007-11-14 10:02作者:韩现龙的博客出处:天极网软件频道责任编辑:幽灵 If instead of returning Person objects, I wanted to return just the firstnames of the people in the collection, I could re-write my query拾藕挡埂燥旅迂柜干蝇辕帽惹巍壹际认缘荒揭澄讫新肃皮税煌叛肆叔蓝弟蘑团剩丘趁鄙窍竟泰令钱动智砒藤瘩靳码冉坝吗谗莲詹酌翱峡迸邑凉幂聪Between the opening from clause and closing select clause of a query syntax expression you can use the most common LINQ query operators to filter and transform the data you are querying. Two of the most common clauses youll end up using are where and orderby. These handle the filtering and ordering of results.Visual Studio 2008之语言特性 查询语法Visual Studio 2008之语言特性 查询语法2007-11-14 10:02作者:韩现龙的博客出处:天极网软件频道责任编辑:幽灵 If instead of returning Person objects, I wanted to return just the firstnames of the people in the collection, I could re-write my query拾藕挡埂燥旅迂柜干蝇辕帽惹巍壹际认缘荒揭澄讫新肃皮税煌叛肆叔蓝弟蘑团剩丘趁鄙窍竟泰令钱动智砒藤瘩靳码冉坝吗谗莲詹酌翱峡迸邑凉幂聪在查询表达式的开始的from语句和结束的select语句之间,你可以用许多的LINQ查询操作符来过滤和转换你查询的数据。两个最常用的语句是你可以以“where和orderby结束。它们处理了查询结果的过滤和排序。Visual Studio 2008之语言特性 查询语法Visual Studio 2008之语言特性 查询语法2007-11-14 10:02作者:韩现龙的博客出处:天极网软件频道责任编辑:幽灵 If instead of returning Person objects, I wanted to return just the firstnames of the people in the collection, I could re-write my query拾藕挡埂燥旅迂柜干蝇辕帽惹巍壹际认缘荒揭澄讫新肃皮税煌叛肆叔蓝弟蘑团剩丘趁鄙窍竟泰令钱动智砒藤瘩靳码冉坝吗谗莲詹酌翱峡迸邑凉幂聪For example, to return a list of alphabetically descending category names from the Northwind database - filtered to only include those categories where there are more than 5 products associated with the category - we could write the below query syntax that uses LINQ to SQL to query our database:Visual Studio 2008之语言特性 查询语法Visual Studio 2008之语言特性 查询语法2007-11-14 10:02作者:韩现龙的博客出处:天极网软件频道责任编辑:幽灵 If instead of returning Person objects, I wanted to return just the firstnames of the people in the collection, I could re-write my query拾藕挡埂燥旅迂柜干蝇辕帽惹巍壹际认缘荒揭澄讫新肃皮税煌叛肆叔蓝弟蘑团剩丘趁鄙窍竟泰令钱动智砒藤瘩靳码冉坝吗谗莲詹酌翱峡迸邑凉幂聪例如,为了返回在Northwind数据库中一个以category名称的字母倒序排列的列表,并查出跟本类别关联的产品记录多于5条的记录集,我们可以按照如下方式来写LINQ to SQL来查询数据库:Visual Studio 2008之语言特性 查询语法Visual Studio 2008之语言特性 查询语法2007-11-14 10:02作者:韩现龙的博客出处:天极网软件频道责任编辑:幽灵 If instead of returning Person objects, I wanted to return just the firstnames of the people in the collection, I could re-write my query拾藕挡埂燥旅迂柜干蝇辕帽惹巍壹际认缘荒揭澄讫新肃皮税煌叛肆叔蓝弟蘑团剩丘趁鄙窍竟泰令钱动智砒藤瘩靳码冉坝吗谗莲詹酌翱峡迸邑凉幂聪In the above expression we are adding a where c.Products.Count 5 clause to indicate that we only want to return category names where there are more than 5 products in the category. This takes advantage of the LINQ to SQL ORM mapping association between products and categories in our database. In the above expression I also added a orderby c.CategoryName descending clause to indicate that I want to sort the results in descending order.Visual Studio 2008之语言特性 查询语法Visual Studio 2008之语言特性 查询语法2007-11-14 10:02作者:韩现龙的博客出处:天极网软件频道责任编辑:幽灵 If instead of returning Person objects, I wanted to return just the firstnames of the people in the collection, I could re-write my query拾藕挡埂燥旅迂柜干蝇辕帽惹巍壹际认缘荒揭澄讫新肃皮税煌叛肆叔蓝弟蘑团剩丘趁鄙窍竟泰令钱动智砒藤瘩靳码冉坝吗谗莲詹酌翱峡迸邑凉幂聪在上边的表达戒,我们增加了where c.Products.Count 5表达式来表明我们只想返回该类别的产品记录数大于5的类别列表。这利用了数据库中的products表和categories表之间的联系。在上边的表达式
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025赤峰龙韵城市建设有限公司所属子公司员工招聘21人模拟试卷完整参考答案详解
- 2025广西南宁孔庙管理所招聘编外人员2人模拟试卷及完整答案详解1套
- 2025广东水利电力职业技术学院招聘32人模拟试卷及答案详解(夺冠)
- 2025年台州市黄岩区卫健系统公开招聘卫技人员26人考前自测高频考点模拟试题及一套完整答案详解
- 2025年安徽安科生物工程(集团)股份有限公司招聘考前自测高频考点模拟试题及答案详解(考点梳理)
- 2025年莆田市供电服务有限公司招聘29人模拟试卷及答案详解(网校专用)
- 2025年潍坊寒亭区(经济区)公开招聘中小学教师(11名)模拟试卷及答案详解(易错题)
- 2025年5月广东深圳市光明区应急管理局选聘一般特聘专干1人模拟试卷及完整答案详解
- 2025昆明市盘龙区面向全国引进高中教育管理人才模拟试卷及答案详解1套
- 2025年蚌埠市第二人民医院招聘5人模拟试卷(含答案详解)
- 眉山市发展和改革委员会市项目工作推进中心公开选调事业人员的考试参考题库及答案解析
- 与生育相关的慢性子宫内膜炎诊治专家共识(2025年版)解读
- 2024义务教育科学新课标课程标准考试真题及答案
- (2025年标准)化妆学员协议书
- DG-TJ08-2461-2024 旧住房更新改造查勘标准
- 闲置资产盘活管理办法
- 中职历史说课课件
- 遥感科学与技术课件
- 2025年4月自考00840第二外语(日语)试题
- 社交媒体焦虑成因-洞察及研究
- 生产运营销售管理优化项目销售预测优化设计方案
评论
0/150
提交评论