项目中及Linq 学习过程中知识点

1:linq join on 后多个条件

方法1: on new{o.id,0.code} equals new {p.id,p.code}

var query= from cc in COPTC

          join cd in COPTD

          on new {cc.TC001,cc.TC002} equals new{ cd.TD001,cd.TD002}

          into m

          from n in m.DefaultIfEmpty()

          join ma in MOCTA

          on new{cd.TD001, cd.TD002,cd.TD003 } equals new{ ma.TA026,ma.TA027,ma.TA028}  

          where new char[]{'Y','y'}.Contains(ma.TA013)

              && newchar[]{'Y','y'}.Contains(cc.TC027)

              &&Convert.ToDateTime(ma.TA003) > Convert.ToDateTime("2010-07-20")

              && Convert.ToDateTime(ma.TA003)< Convert.ToDateTime("2010-12-31")

          select new

          {

              cc,

              cd

          };
方法2:
var tmp=from m in table1 from n in table2 where m.id==n.id && m.code==n.code select new{...};
方法3
把条件放在where语句里面去.

2:Linq 101 个例子

下载地址:http://code.msdn.microsoft.com/101-LINQ-Samples-3fb9811b/viewsamplepack

 

3:Linq ExecuteQuery方法执行结果的枚举问题

方法1:

1、IExecuteQuery<T>中T类的字段名必须与sql_exp中SQL语句的列名一样才能填充实体类。

 

2、执行ExecuteQuery()返回的IExecuteQuery<T>不能进行多次(两次以上)结果集查询,且读取IExecuteQuery<T>必须保持connecton open,所以考虑转化为IList<T>。

 

使用时,可先将结果缓存到IList对象中。如下示例

 

IEnumerable<T> search = conn.ExecuteQuery<T>(sqlCommond);

 

IList<T> alist=newList<T>(search);

3http://social.msdn.microsoft.com/Forums/en-US/f403e047-e38c-45ab-9155-dbf83c6cc2fa/the-query-results-cannot-be-enumerated-more-than-once?forum=linqprojectgeneral

 

4:检测到有潜在危险的Request.Form 值解决方法

方法1:在PAGE 页面加上:
<% Page ValidateRequest="false" %>
方法2:也可以在WEB.CONFIG 中加上[推荐]:
<configuration>
<system.web>
<pages validateRequest="false" />
</system.web>
<configuration>   注意,一般web.config已经有了<system.web>这个tag,这时只需要把<pagesvalidateRequest="false" />复制到这个tag以下就可以禁止.net进行请求验证了。

方法3:http://msdn.microsoft.com/zh-cn/library/hh882339.aspx

 

5:Linq数据实体外部更新时“不能添加其键已在使用中的实体”的解决办法

 

http://www.cnblogs.com/yjmyzz/archive/2009/04/20/1440014.html

 

6: Linq to Sql : 三种事务处理方式

http://www.cnblogs.com/happyhippy/archive/2010/01/27/1657552.html

7: linq To Sql之关联表同步添加数据及主从表插入

http://blog.sina.com.cn/s/blog_3d7bed650102e3xa.html

http://blog.csdn.net/longer123123/article/details/3954495

 

8:Linq to Sql重复行数据合并为一行,数据用逗号分隔 

http://blog.163.com/heaver_1989/blog/static/184604338201211145913963/

 

9:其他

1:判断是否英文字母或数字的C#正则表达式

publicbool IsNatural_Number(string str)
        {
           System.Text.RegularExpressions.Regex reg1 = newSystem.Text.RegularExpressions.Regex(@"^[A-Za-z0-9]+$");
            returnreg1.IsMatch(str);
        }

2:匹配数字字母汉字

var reg:RegExp =/^[a-zA-Z0-9\u4e00-\u9fa5]+$/;
trace(reg.test("test你好hello")); //output "true"

如果要仅仅匹配汉字和字母,正则可以写成 /^[a-zA-Z\u4e00-\u9fa5]+$/。
[\u4e00-\u9fa5]是unicode编码中双字节汉字部分,标记一下。

 

3: DataView.RowFilter的使用(包括in,like等SQL中的操作符)

http://hi.baidu.com/bluelight68/item/aab1e0e322c7093e4ddcaf9d

http://liug-li.blog.163.com/blog/static/2154166201241012941269/

4: jQuery Autocomplete模拟百度google模糊查询

http://www.cnblogs.com/yuzhongwusan/archive/2012/06/04/2534262.html

http://q.cnblogs.com/q/45390/


版权声明:本文为kongwei521原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。