如何即时构建 WCF 查询?
我想构建一些 linq,或者动态构建一个查询字符串并将其传递给 WCF 数据服务(使用实体框架数据模型)。
像这样的东西:
public List<DocumentInformationRecord> SearchClientDocs(string clientCode,
string clientName, string contactName, string groupCode, string groupName,
string filename, string createdby, DateTime dateFrom, DateTime dateTo)
{
List<DocumentInformationRecord> results = new List<DocumentInformationRecord>();
if(!string.IsNullOrEmpty(clientCode))
//Add the client code clause...
等等..
var qry = from c in context.DocumentInformationRecord.where(dynamicQuery);
//Etc......
有什么想法吗?我尝试了谓词构建器(http://www.albahari.com/nutshell/predicatebuilder.aspx< /a>) 但得到了一些无效操作异常......
I'd like to build some linq or alternatively, build a query string on the fly and pass it to a WCF Data Service (with Entity Framework data model).
Something like this:
public List<DocumentInformationRecord> SearchClientDocs(string clientCode,
string clientName, string contactName, string groupCode, string groupName,
string filename, string createdby, DateTime dateFrom, DateTime dateTo)
{
List<DocumentInformationRecord> results = new List<DocumentInformationRecord>();
if(!string.IsNullOrEmpty(clientCode))
//Add the client code clause...
etc..
var qry = from c in context.DocumentInformationRecord.where(dynamicQuery);
//Etc......
Any ideas? I tried the predicate builder (http://www.albahari.com/nutshell/predicatebuilder.aspx) but got some invalid operation exceptions.....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定我完全理解你的问题,但我有时会编写代码来根据输入的不同部分构建 LINQ 查询。通常情况是这样的:
这样您就可以逐步构建查询。您可以这样做是因为延迟执行;在开始迭代结果之前,不会对数据源执行查询。
I am not sure I entirely understand your question, but I have sometimes written code to build up LINQ queries with different parts depending on input. Typically that goes something like this:
That way you can build the query step by step. You can do this because of deferred execution; the query will not be executed against the data source until you start iterating over the result.
不确定它是否适合您的情况,但您可以使用表达式树来构建动态查询。这里有一个很好的教程
Not sure if it will suit your situation, but you can use expression trees to build dynamic queries. There is a good tutorial here