linq 出错 如何解决
以下代码 没有查询出想要的结果 如何修改
想要查询的内容是 <Layout direction="Vertical"> 这个小结
代码部分
XName Form = "Form", Id = "id", Control = "Control", Layout = "Layout", direction = "direction", Location = "Location", x = "x", y = "y", Size="Size",width = "width", height = "height";
string FormID = "FormLogin", ControlID = "panelMain", Direction = "Vertical";
//IEnumerable<string> partNos = Elements
var LocationList = from Forms in Root.Elements(Form)
where
( (string)Forms.Attribute(Id) == FormID &&
(string)Forms.Element(Control).Attribute(Id) == ControlID &&
(string)Forms.Element(Control).Element(Layout).Attribute(direction) == Direction
)
select new{
X =(int)Forms.Element(Control).Element(Layout).Element(Location).Element(x),
Y =(int)Forms.Element(Control).Element(Layout).Element(Location).Element(y),
Width = (int)Forms.Element(Control).Element(Layout).Element(Size).Element(width),
Height = (int)Forms.Element(Control).Element(Layout).Element(Size).Element(height),
};
xml文件
<?xml version="1.0" encoding="utf-8" ?>
<Root>
<!--登录窗口-->
<Form id="FormLogin" type="Form">
<!--panel控件-->
<Control id ="panelMain" type="Panel">
<Layout direction="Traverse">
<Location>
<x>3</x>
<y>3</y>
</Location>
<Size>
<width>234</width>
<height>262</height>
</Size>
</Layout>
<Layout direction="Vertical">
<Location>
<x>4</x>
<y>34</y>
</Location>
<Size>
<width>234</width>
<height>262</height>
</Size>
</Layout>
</Control>
</Form>
</Root>
想要查询的内容是 <Layout direction="Vertical"> 这个小结
代码部分
XName Form = "Form", Id = "id", Control = "Control", Layout = "Layout", direction = "direction", Location = "Location", x = "x", y = "y", Size="Size",width = "width", height = "height";
string FormID = "FormLogin", ControlID = "panelMain", Direction = "Vertical";
//IEnumerable<string> partNos = Elements
var LocationList = from Forms in Root.Elements(Form)
where
( (string)Forms.Attribute(Id) == FormID &&
(string)Forms.Element(Control).Attribute(Id) == ControlID &&
(string)Forms.Element(Control).Element(Layout).Attribute(direction) == Direction
)
select new{
X =(int)Forms.Element(Control).Element(Layout).Element(Location).Element(x),
Y =(int)Forms.Element(Control).Element(Layout).Element(Location).Element(y),
Width = (int)Forms.Element(Control).Element(Layout).Element(Size).Element(width),
Height = (int)Forms.Element(Control).Element(Layout).Element(Size).Element(height),
};
xml文件
<?xml version="1.0" encoding="utf-8" ?>
<Root>
<!--登录窗口-->
<Form id="FormLogin" type="Form">
<!--panel控件-->
<Control id ="panelMain" type="Panel">
<Layout direction="Traverse">
<Location>
<x>3</x>
<y>3</y>
</Location>
<Size>
<width>234</width>
<height>262</height>
</Size>
</Layout>
<Layout direction="Vertical">
<Location>
<x>4</x>
<y>34</y>
</Location>
<Size>
<width>234</width>
<height>262</height>
</Size>
</Layout>
</Control>
</Form>
</Root>
...全文
相关推荐
深入浅淡LINQ
深入浅淡LINQ 电子书。 适合LINQ初学者,或作为程序开发参考手册。
深入浅出谈LINQ
LINQ 提供了一条更常规的途径即给 .Net Framework 添加一些可以应用于所有信息源( all sources of information )的具有多种用途( general-purpose )的语法查询特性( query facilities ),这是比向开发语言和运行时( runtime )添加一些关系数据( relational )特性或者类似 XML 特性( XML-specific )更好的方式。这些语法特性就叫做 .NET Language Integrated Query (LINQ) 。
Linq中文文档(超值)
详细介绍LINQ to SQL,LINQ to XML,LINQ to Object,LINQ to ADO.net等等LINQ的详细语法及用法
LINQ手册
一本介绍LINQ的手册~适合入门!
MD.Linq2Access.English.rar_english_linq2access_linq2md
自定义linq实例,支持access sqlserver 等


LINQ
