简体   繁体   English

VB.net linq。包含在XML列上

[英]VB.net linq .contains on XML column

I have a database with one XML column named Results. 我有一个带有一个名为Results的XML列的数据库。 This column contains results from factory testing and different XML formatting depending on which test was performed. 此列包含工厂测试的结果以及根据执行的测试而不同的XML格式。

I'm developing a GUI where I can browse my results so I need to filter this column dynamically. 我正在开发一个GUI,可以在其中浏览结果,因此需要动态过滤此列。

My first idea was to use Results.contains("myfilter") but this does not seem to work. 我的第一个想法是使用Results.contains("myfilter")但这似乎不起作用。

I am using Visual Studio 2015 with linq and entities. 我正在使用带有linq和图元的Visual Studio 2015。

This is my query: 这是我的查询:

Using context As New Entities
    Dim query = From tr In context.TestResults
                Join t In context.Tests On a Equals tr.Tests
                Join ts In context.TestStations On ts Equals tr.TestStations
                Join ut In context.UnitTraveler On ut Equals tr.UnitTraveler
                Where t.Id = TestID
                Where ts.Id = TestStationID
                Where tr.Results.Contains("TestCurrent")
                Take Count
                Select ut.SerialNumber, ut.ModelString, ut.Passed, tr.Results, tr.StartedOn, tr.EndedOn
                Order By StartedOn Descending
End Using

Update 2015-12-01: I still haven't found a solution to this. 2015年12月1日更新:我仍然没有找到解决方案。 Does anyone have an idea? 有人有主意吗?

If the Results property is of type String and you search inside this string for a specific substring you can use this: 如果Results属性的类型为String并且在此字符串中搜索特定的子字符串,则可以使用以下命令:

query = (From tr In ... Where tr.Results Like "*TestCurrent*")

If Results it is a collection or List 如果结果是集合或列表

query = (From tr In ... Where tr.Results.Find(Function(f As Result) f.Contents Like "*TestCurrent*") IsNot Nothing)

Please change the used words Result and Contents according to your Classnames and Properties. 请根据您的类名和属性更改使用的单词“结果”和“内容”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM