Linq Lambda到XML的连接表达式
我有一个XML文件,格式如下Linq Lambda到XML的连接表达式,linq,linq-to-xml,Linq,Linq To Xml,我有一个XML文件,格式如下 <?xml version="1.0" encoding="utf-8"?> <root> <EntityType_Data> <EntityType> <ID>1</ID> <Caption>Entity1</Caption> <Description>Entity1</Description>
<?xml version="1.0" encoding="utf-8"?>
<root>
<EntityType_Data>
<EntityType>
<ID>1</ID>
<Caption>Entity1</Caption>
<Description>Entity1</Description>
<ModuleID>3</ModuleID>
<Category>1</Category>
</EntityType>
<EntityType>
<ID>2</ID>
<Caption>Entity2</Caption>
<Description>Entity2</Description>
<ModuleID>3</ModuleID>
<Category>1</Category>
</EntityType>
<EntityType>
<ID>3</ID>
<Caption>Entity4</Caption>
<Description>Entity4</Description>
<ModuleID>3</ModuleID>
<Category>1</Category>
</EntityType>
<EntityType>
<ID>4</ID>
<Caption>Entity5</Caption>
<Description>Entity5</Description>
<ModuleID>3</ModuleID>
<Category>1</Category>
</EntityType>
</EntityType_Data>
<AttributeType_Table>
<AttributeType>
<ID>1</ID>
<Caption>AttributeType1</Caption>
<DataType>string</DataType>
<SqlType>nvarchar(max)</SqlType>
</AttributeType>
<AttributeType>
<ID>1</ID>
<Caption>AttributeType2</Caption>
<DataType>integer</DataType>
<SqlType>int</SqlType>
</AttributeType>
</AttributeType_Table>
<Attributes_Table>
<Attribute>
<ID>1</ID>
<Caption>SingleLineTextbox</Caption>
<AttributeTypeID>1</AttributeTypeID>
</Attribute>
<Attribute>
<ID>2</ID>
<Caption>MultiLineTextBox</Caption>
</Attribute>
<Attribute>
<ID>3</ID>
<Caption>OrgLevel</Caption>
<AttributeTypeID>3</AttributeTypeID>
</Attribute>
</Attributes_Table>
<EntityRelationtable>
<EntityTypeAttributeRelation>
<EntityTypeID>2</EntityTypeID>
<AttributeID>1</AttributeID>
</EntityTypeAttributeRelation>
<EntityTypeAttributeRelation>
<EntityTypeID>3</EntityTypeID>
<AttributeID>2</AttributeID>
</EntityTypeAttributeRelation>
<EntityTypeAttributeRelation>
<EntityTypeID>3</EntityTypeID>
<AttributeID>1</AttributeID>
</EntityTypeAttributeRelation>
<EntityTypeAttributeRelation>
<EntityTypeID>3</EntityTypeID>
<AttributeID>3</AttributeID>
</EntityTypeAttributeRelation>
<EntityTypeAttributeRelation>
<EntityTypeID>2</EntityTypeID>
<AttributeID>2</AttributeID>
</EntityTypeAttributeRelation>
</EntityRelationtable>
</root>
我正在考虑将这个结果与“AttributeType_Table”元素“AttributeID”结合起来,最后我用with linq query only而不是linq Lambda解决了我的问题
var attributeresult = from a in workingXmldoc.Descendants("EntityRelationtable").Elements("EntityTypeAttributeRelation")
join b in workingXmldoc.Descendants("Attributes_Table").Elements("Attribute")
on (string)a.Element("AttributeID") equals (string)b.Element("ID")
join c in workingXmldoc.Descendants("Attributetype_Table").Elements("AttributeType")
on (string)b.Element("AttributeTypeID") equals (string)c.Element("ID")
where (string)a.Element("EntityTypeID") == "" + entitytypeId + ""
select new {
AttributeID = a.Element("AttributeID").Value,
AttributeName = b.Element("Caption").Value,
AttributeDatatype = c.Element("DataType").Value,
AttributeSqltype = c.Element("SqlType").Value
};
如果有人给了Linq lambda一个值得欣赏的查询..最后我用with Linq query only而不是Linq lambda解决了我的问题
var attributeresult = from a in workingXmldoc.Descendants("EntityRelationtable").Elements("EntityTypeAttributeRelation")
join b in workingXmldoc.Descendants("Attributes_Table").Elements("Attribute")
on (string)a.Element("AttributeID") equals (string)b.Element("ID")
join c in workingXmldoc.Descendants("Attributetype_Table").Elements("AttributeType")
on (string)b.Element("AttributeTypeID") equals (string)c.Element("ID")
where (string)a.Element("EntityTypeID") == "" + entitytypeId + ""
select new {
AttributeID = a.Element("AttributeID").Value,
AttributeName = b.Element("Caption").Value,
AttributeDatatype = c.Element("DataType").Value,
AttributeSqltype = c.Element("SqlType").Value
};
如果有人给Linq lambda一个值得注意的查询..我想把这个结果和“AttributeType_Table”元素“AttributeID”连接起来。@srinivasadari:请用这个代码更新你的问题。别忘了告诉我们你在这段代码中遇到了什么问题。我想把这个结果和“AttributeType_Table”元素“AttributeID”结合起来。@srinivasadari:请用这段代码更新你的问题。别忘了告诉我们你在代码中遇到了什么问题。