Quantcast
Channel: Linq Lambda join expression to XML - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Linq Lambda join expression to XML

$
0
0

I have an XML file in the following format

<?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>

Now I want to get the data filter "EntityTypeID" and "AttributeID" from "EntityRelationtable" element using where condition after that based on "AttributeID" need to get "Caption","Datatype" from "AttributeType_Table" element and need to get "Description" from "EntityType_Data" element.

I'm have to do that above requirement using Linq lambda expression.Please solve it only by linq with lambda.

so far I tried to get "EntityTypeID" and "AttributeID" from "EntityRelationtable" element.

var attributeresult = workingXmldoc  .Descendants("EntitytypeAttributeRelation_Table")  .Elements("EntityT‌​ypeAttributeRelation")  .Where(x => x.Element("EntityTypeID").Value == ""+ entitytypeId +"")  .Select(v => new { EntitytypeID = v.Element("EntityTypeID").Value, AttributeID = v.Element("AttributeID").Value }); 

I'm thinking to join this result with the "AttributeType_Table" element "AttributeID".


Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>