Linqdatasource中的selecting event与where条件关系

linqdatasource是个好东西。

用这个,分页、排序、更新等算法都不用自己写了。

而且,还提供了很多事件供我们进行更细致的控制。

其中,提供的selecting event事件最为常用。经常有界面,需要根据用户输入的条件,来过滤显示的记录,这时,selecting event就派上用场了。

可以说这是最为常见的用法。

但是 ,这个selecting event和linqdatasource中定义的where参数条件是什么关系呢?

用sql profile一跟踪,马上清晰了。

比如在where中定义了:

 

<linqdatasouce  
            Where
="create_userid == @create_userid" 
            onselecting
="LinqDataSource1_Selecting">
            
<WhereParameters>
                
<asp:SessionParameter DefaultValue="0" Name="create_userid" 
                    SessionField
="userid" Type="Int32" />
            
</WhereParameters>

在selectingevent中定义:

var r = from t in this.xxx
                    
where t.document_no.Contains(docno)
                    
&& t.create_time > createTimeStart
                    
&& t.tb_user_create.name.Contains(createUserName)
                    
&& t.status.Contains(digiStatus)
                    orderby t.document_no descending
                    select t;
            
return r;

 

生成的sql语句,就是

 select count(*) from xxx where  ([t0].[create_userid] = @p0) AND ...(这里是自己在selecting event中定义的各种条件)

 linq真是好东西。当然,离不开sql profile。

呵呵,有啥不明白的,一跟,全清晰了。

posted on 2008-10-15 20:55  daimon  阅读(732)  评论(0)    收藏  举报

导航