linq查询有两个条件 [英] linq query with two conditions

查看:405
本文介绍了linq查询有两个条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Visual Studio 2010 .net 4和WPF



我从名为BeforeSortDocument的流文档中获取了名为FavoriteBookmarksCollection的段落名称集合。



对于FavoriteBookmarkCollection中的每个项目,该项目将被修改为代表段落名称S语言以从流文档中获取段落,同样的项目将再次修改为代表英语,是另一种语言的翻译。



段落的首选是S语言,后面跟着E语言。我必须使用linq查询从BeforeSortDocument中选择两个段落到另一个文档中。



我在VB.net中的不工作查询是:

Using Visual Studio 2010 .net 4 and WPF

I have collection of names of paragraphs named as FavoriteBookmarksCollection drawn from a flowdocument named as BeforeSortDocument .

For each item in FavoriteBookmarkCollection, the item will be modified to represent a paragraph name of "S" language to get the paragraph from the flowdocument and also the same item will be again modified to represent English Language which is a translation of the other language.

First selection of paragraph is "S" language and followed by "E" language. I have to select both the paragraphs from BeforeSortDocument into another document using linq query.

My not working query in VB.net is:

dim RequiredParaCollection = (From para in ParasOfBeforeSortDocument
where (Regex.IsMatch(para.name,"B\d{4}S\d{2}") Or regex.ismatch(para.name,"B\d{4}E\d{2}")
Select ctype(LogicalTreeHelper.FindLogicalNode(BeforeSortDocument,para.name)).ToList()



ParasOfBeforeSortDocument是一个readonlyCollection(段落)并且没问题。

BeforeSortDocument是flowdocument并且没有任何错误。



我请求你的帮助在'Where'中写下两个条件,一个跟随另一个,并按顺序得到文件的段落。



Ť hanx


ParasOfBeforeSortDocument is a readonlyCollection(of Paragraph) and is OK.
BeforeSortDocument is flowdocument and is without any error.

I request help from YOU to write two conditions in 'Where' one follows another and get the paragraphs of the document in that order.

Thanx

推荐答案

我建​​议下载: LINQ - 示例查询 [ ^ ]。在那里你会找到101个例子;)



请看看这里:
Linq:Where子句(VB) [ ^ ]在这里:如何:将LINQ查询与常规相结合表达式 [ ^ ]。我想,你错误地将 regex 结合起来。



使用具有正则表达式结果的Linq [ ^ ]



祝你好运!
I'd suggest to download: LINQ - Sample Queries[^]. There you'll find 101 examples ;)

Please, have a look here: Linq: Where clause (VB)[^] and here: How to: Combine LINQ Queries with Regular Expressions[^]. I think, you do combine where and regex in wrong way.

Using Linq with Regular Expression results[^]

Good luck!


使用正则表达式查询的链接很好。就我而言,它变得更加复杂。所以我使用非正则表达式查询解决了这个问题。

我在单行中使用linq的解决方案

dim paraList =(来自书签中的x选择x

让sanskritParaName = skeletonId + Format(value,00)

来自para in para,其中para is not nothing andalso(para.name.equals(x)或para.name.equals(sanskritParaName.replace( S,E))也不是bookmarkCollection.contains(x)

让englishtext = sanskritParaName.Substring(1,4)+ If(value< 10,0, )

设f = ModifiedParagraphUtility(para,englishtext)

选择f).ToList

这完美无缺。我使用变体测试了它。最后我将paraList添加到文档块。

谢谢。
The link using regex queries is good. In my case, it has become more complex. So I solved this using non regex queries.
My solution using linq in single line
dim paraList =(from x in bookmarks select x
Let sanskritParaName = skeletonId + Format(value, "00")
from para in paras where para isnot nothing andalso (para.name.equals(x) or para.name.equals(sanskritParaName.replace("S","E")) andalso not bookmarkCollection.contains(x)
Let englishtext = sanskritParaName.Substring(1, 4) + If(value < 10, "0", "")
Let f = ModifiedParagraphUtility(para, englishtext)
Select f).ToList
This has worked perfectly. I tested it using variations. Finally I added paraList to document blocks.
Thanks.


这篇关于linq查询有两个条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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