LINQ to SQL中的动态where语句 [英] dynamic where statement in linq to sql

查看:85
本文介绍了LINQ to SQL中的动态where语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好亲爱的CPians,

我在一个页面上工作,用户将为我的水晶报表选择一些过滤选项.因此,无法提前知道where语句.在过去的3个小时中,我一直试图弄清楚我该如何做到这一点.谁能帮助我该怎么做:

我需要一些东西:

Hello dear CPians,

I work on a page that user will choose some filtering options for my crystal report. So the where statement can not be known ahead of time. i have been trying to figure out how i can accomplish this for the past 3 hours. can anyone help me how i can do this:

I need something:

var queryTestLast = from r in db.vwGetReportByFilters
                    where + strWhereStatement 
                    select new 
                    {
                      r.orderNum, 
                      r.ticketNum
                    };

推荐答案



为什么不将datetime参数传递给Crystal报表?
将报告日期时间与实际日期进行比较将是一项非常容易的任务.

问候
Hi,

Why not passing datetime parameter to your crystal report?
It would be an quite easy task to compare report datetime with actual.

Regards


您最好的选择是使用基于条件的动态表达式来过滤where子句并使用linq的方法语法.

http://www.marcuswhitworth.com/2009/12/dynamic-linq-with -expression-trees/ [ ^ ]

http://www.digitallycreated.net/Blog/37/dynamic-queries-in-entity-framework-using-expression-trees [ http://tomasp.net/blog/dynamic-linq-queries.aspx [ ^ ]
Your best bet is to use dynamic Expressions based on criteria to filter your where clause and use the method syntax of linq.

http://www.marcuswhitworth.com/2009/12/dynamic-linq-with-expression-trees/[^]

http://www.digitallycreated.net/Blog/37/dynamic-queries-in-entity-framework-using-expression-trees[^]

http://tomasp.net/blog/dynamic-linq-queries.aspx[^]


这篇关于LINQ to SQL中的动态where语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆