LINQ to DataSet 和 xml 帮助
我在数据集设计器中创建了一个强类型数据集。 DataSet 有一个名为 FocusOffsetsTable 的表,该表有四列;序列号、过滤器、轮子和偏移量。我使用 DataSet 类的 ReadXml() 方法将强类型数据从 xml 文件加载到数据集中。这似乎工作得很好。
我正在尝试使用 LINQ 表达式来尝试从此表中获取单行,但我似乎无法获得正确的语法。我想使用 Single()
或 SingleOrDefault()
方法一次仅获取一行数据,但我不确定如何操作。
我已经尝试过这个 FocusOffsets.FocusOffsetsTableRow x = FocusOffsetData.FocusOffsetsTable.
但 Single() 方法在这里不可用。我也尝试过这个...
FocusOffsets.FocusOffsetsTableRow x = (from offset in FocusOffsetData.FocusOffsetsTable
where offset.SerialNumber == mydevice.SerialNumber
where offset.Wheel == WheelID
where offset.Filter == FilterNum
select offset).Single();
但是 Single 方法在这里也不可用。
我之前曾对 SQL 数据库中的表执行过此操作,但这是我第一次使用数据集设计器中的数据集。
I created a strongly-typed dataset in the dataset designer. The DataSet has a Table called FocusOffsetsTable and that table has four colums; SerialNumber, Filter, Wheel and Offset. I use the ReadXml() method of the DataSet class to load the strongly typed data from the xml file into the dataset. That seems to be working just fine.
I am trying to use a LINQ expression to try to get a Single row from this table but I can't seem to get the syntax correct. I want to use the Single()
or SingleOrDefault()
method to get just one row of data at a time but I am not sure how.
I have tried this FocusOffsets.FocusOffsetsTableRow x = FocusOffsetData.FocusOffsetsTable.
but the Single() method is not available here. I also tried this...
FocusOffsets.FocusOffsetsTableRow x = (from offset in FocusOffsetData.FocusOffsetsTable
where offset.SerialNumber == mydevice.SerialNumber
where offset.Wheel == WheelID
where offset.Filter == FilterNum
select offset).Single();
but the Single method is not available here either.
I have done this before with tables in a SQL database before but this is my first time using a dataset from the dataset designer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否为 System.Linq 添加了
using
语句并包含对 System.Data.DataSetExtensions 的引用。我认为(但无法确认,因为我使用的是 Mac),您应该能够执行以下操作:Have you added a
using
statement for System.Linq and included a reference to System.Data.DataSetExtensions. I think (but can't confirm since I'm on my Mac), that you ought to be able to do: