ram27
asked on
LINQ query to bind the XML data into pivot datagrid
Hi,
I have an XML which is is like below
basically what i need to do here is : I need to write a LINQ query
To bind the above XML data to the datagrids in silverlight
For Statistic type CT, i need to bind the grid like below
Corporations Revoked Corps Delinquent Corps
Foreign 58897((i,e) ForeignCorporation 10480 934
Statistic code)
Domestic 550861 6 4540
Please i am new to LINQ, please help me to write a LINQ query to bind the above XML data to the datagrid like above
Thanks
I have an XML which is is like below
<Root xmlns="Acc.StarPlus.XsdLibrary">
<PublicCountStatistic>
<StatisticCode xmlns="Acc.StarPlus.XsdLibrary">
<CategoryId>70</CategoryId>
<CategoryValueId>2101</CategoryValueId>
<DisplayCode>1</DisplayCode>
<DisplayName>FOREIGN REVOKED CORPS </DisplayName>
<EnumName>FOREIGNREVOKEDCORPS</EnumName>
<IsActive>1</IsActive>
<SortOrder>1</SortOrder>
</StatisticCode>
<StatisticCount>10480</StatisticCount>
<StatisticDate>2009-12-31T00:00:00</StatisticDate>
<StatisticType>CT</StatisticType>
</PublicCountStatistic>
<PublicCountStatistic>
<StatisticCode xmlns="Acc.StarPlus.XsdLibrary">
<CategoryId>70</CategoryId>
<CategoryValueId>2102</CategoryValueId>
<DisplayCode>2</DisplayCode>
<DisplayName>DOMESTIC REVOKED CORPORATIONSDisplayName>
<EnumName>DOMESTICREVOKEDCORPORATIONS<EnumName>
<IsActive>1</IsActive>
<SortOrder>1</SortOrder>
</StatisticCode>
<StatisticCount>6</StatisticCount>
<StatisticDate>2009-12-31T00:00:00</StatisticDate>
<StatisticType>CT</StatisticType>
</PublicCountStatistic>
<PublicCountStatistic>
<StatisticCode xmlns="Acc.StarPlus.XsdLibrary">
<CategoryId>70</CategoryId>
<CategoryValueId>2104</CategoryValueId>
<DisplayCode>4</DisplayCode>
<DisplayName>FOREIGN DELINQUENT CORPS<DisplayName>
<EnumName>FOREIGNDELINQUENTCORPS</EnumName>
<IsActive>1</IsActive>
<SortOrder>1</SortOrder>
</StatisticCode>
<StatisticCount>934</StatisticCount>
<StatisticDate>2009-12-31T00:00:00</StatisticDate>
<StatisticType>CT</StatisticType>
</PublicCountStatistic>
<PublicCountStatistic>
<StatisticCode xmlns="Acc.StarPlus.XsdLibrary">
<CategoryId>70</CategoryId>
<CategoryValueId>2105</CategoryValueId>
<DisplayCode>5</DisplayCode>
<DisplayName>DOMESTIC DELINQUENT CORPS </DisplayName>
<EnumName>DOMESTICDELINQUENTCORPS</EnumName>
<IsActive>1</IsActive>
<SortOrder>1</SortOrder>
</StatisticCode>
<StatisticCount>4540</StatisticCount>
<StatisticDate>2009-12-31T00:00:00</StatisticDate>
<StatisticType>CT</StatisticType>
</PublicCountStatistic>
<PublicCountStatistic>
<StatisticCode xmlns="Acc.StarPlus.XsdLibrary">
<CategoryId>70</CategoryId>
<CategoryValueId>2106</CategoryValueId>
<DisplayCode>6</DisplayCode>
<DisplayName>FOREIGN CORPORATIONS</DisplayName>
<EnumName>FOREIGNCORPORATIONS</EnumName>
<IsActive>1</IsActive>
<SortOrder>1</SortOrder>
</StatisticCode>
<StatisticCount>58897</StatisticCount>
<StatisticDate>2009-12-31T00:00:00</StatisticDate>
<StatisticType>CT</StatisticType>
</PublicCountStatistic>
<PublicCountStatistic>
<StatisticCode xmlns="Acc.StarPlus.XsdLibrary">
<CategoryId>70</CategoryId>
<CategoryValueId>2107</CategoryValueId>
<DisplayCode>7</DisplayCode>
<DisplayName>DOMESTIC CORPORATIONS</DisplayName>
<EnumName>DOMESTICCORPORATIONS</EnumName>
<IsActive>1</IsActive>
<SortOrder>1</SortOrder>
</StatisticCode>
<StatisticCount>550861</StatisticCount>
<StatisticDate>2009-12-31T00:00:00</StatisticDate>
<StatisticType>CT</StatisticType>
</PublicCountStatistic>
<PublicCountStatistic>
<StatisticCode xmlns="Acc.StarPlus.XsdLibrary">
<CategoryId>70</CategoryId>
<CategoryValueId>2108</CategoryValueId>
<DisplayCode>8</DisplayCode>
<DisplayName>FOREIGN CORPORATIONS ADDED</DisplayName>
<EnumName>FOREIGNCORPORATIONSADDED</EnumName>
<IsActive>1</IsActive>
<SortOrder>1</SortOrder>
</StatisticCode>
<StatisticCount>202</StatisticCount>
<StatisticDate>2009-12-31T00:00:00</StatisticDate>
<StatisticType>MTH</StatisticType>
</PublicCountStatistic>
<PublicCountStatistic>
<StatisticCode xmlns="Acc.StarPlus.XsdLibrary">
<CategoryId>70</CategoryId>
<CategoryValueId>2110</CategoryValueId>
<DisplayCode>10</DisplayCode>
<DisplayName>DOMESTIC CORPORATIONS REINSTATED</DisplayName>
<EnumName>DOMESTICCORPORATIONSREINSTATED</EnumName>
<IsActive>1</IsActive>
<SortOrder>1</SortOrder>
</StatisticCode>
<StatisticCount>225</StatisticCount>
<StatisticDate>2009-12-31T00:00:00</StatisticDate>
<StatisticType>MTH</StatisticType>
</PublicCountStatistic>
basically what i need to do here is : I need to write a LINQ query
To bind the above XML data to the datagrids in silverlight
For Statistic type CT, i need to bind the grid like below
Corporations Revoked Corps Delinquent Corps
Foreign 58897((i,e) ForeignCorporation 10480 934
Statistic code)
Domestic 550861 6 4540
Please i am new to LINQ, please help me to write a LINQ query to bind the above XML data to the datagrid like above
Thanks
This is the perfect teaching opportunity, since you say that you are new to LINQ. How much do you already know about LINQ-to-XML? Have you attempt anything yet? If so, can you show me what you have?
Given the data loaded into an XElement variable, xml
- e.g.
Dim xml as XElement = <Root xmlns="Acc.StarPlus.XsdLib rary">
<PublicCountStatistic>
<StatisticCode xmlns="Acc.StarPlus.XsdLib rary">
...
...
</Root>
The attached two linq statements filter by Type CT and then create an enumerable of with boolean fields indicating the source of each line.
It should be fairly easy then to summarise the data using a further query on ctParsed
- e.g.
Dim xml as XElement = <Root xmlns="Acc.StarPlus.XsdLib
<PublicCountStatistic>
<StatisticCode xmlns="Acc.StarPlus.XsdLib
...
...
</Root>
The attached two linq statements filter by Type CT and then create an enumerable of with boolean fields indicating the source of each line.
It should be fairly easy then to summarise the data using a further query on ctParsed
Dim CT = From x As XElement In xml.Elements(aw + "PublicCountStatistic")
Where x.Element(aw + "StatisticType") = "CT"
Select DisplayCode = x.Element(aw + "StatisticCode").Element(aw + "DisplayCode").Value
Dim ctParsed = From c In CT
Select Foreign = "146".Contains(c),
Revoked = "12".Contains(c), Delinqent = "45".Contains(c), Corporation = "67".Contains(c)
ASKER
Hi All,
Thanks for your replies,
I tried writing the below.. I am taking the XML data into a collection
private void BindDataGrid(ObservableCol lection<GE N.PublicCo untStatist ic> StatisticCount)
{
var pcs = from p in StatisticCount
where p.StatisticType.DisplayCod e == "CT"
group p by new { p.StatisticCode.EnumName }
into pcsdata
select new
{
BusinessCorps = pcsdata.Where(p => p.StatisticCode.EnumName == "DomesticBusinessCorporati ons").Firs tOrDefault ().Statist icCount,
NonProfitCorps = pcsdata.Where(p => p.StatisticCode.EnumName == "DomesticNonProfitCorporat ions").Fir stOrDefaul t().Statis ticCount,
ProfessionalCorps = pcsdata.Where(p => p.StatisticCode.EnumName == "DomesticProfessionalCorpo rations"). FirstOrDef ault().Sta tisticCoun t,
OtherCorps = pcsdata.Where(p => p.StatisticCode.EnumName == "Domestic Other Corporations").FirstOrDefa ult().Stat isticCount
};
dgCurrentStatisticsPart1.I temsSource = pcs;
}
But I am getting some NULl Exception..
Please advice me how to write to bind the data into a PIVOT Grid
And one more thing is if it is a ForeignCorporation it shold display under it(beside the Row header Foreign) and if it is Domestic then beside the Row header Domestic
Thanks,
Thanks for your replies,
I tried writing the below.. I am taking the XML data into a collection
private void BindDataGrid(ObservableCol
{
var pcs = from p in StatisticCount
where p.StatisticType.DisplayCod
group p by new { p.StatisticCode.EnumName }
into pcsdata
select new
{
BusinessCorps = pcsdata.Where(p => p.StatisticCode.EnumName == "DomesticBusinessCorporati
NonProfitCorps = pcsdata.Where(p => p.StatisticCode.EnumName == "DomesticNonProfitCorporat
ProfessionalCorps = pcsdata.Where(p => p.StatisticCode.EnumName == "DomesticProfessionalCorpo
OtherCorps = pcsdata.Where(p => p.StatisticCode.EnumName == "Domestic Other Corporations").FirstOrDefa
};
dgCurrentStatisticsPart1.I
}
But I am getting some NULl Exception..
Please advice me how to write to bind the data into a PIVOT Grid
And one more thing is if it is a ForeignCorporation it shold display under it(beside the Row header Foreign) and if it is Domestic then beside the Row header Domestic
Thanks,
ASKER
Please help me to solve this...
HI,
I have an XML which is is like below
<Root xmlns="Acc.StarPlus.XsdLib
<PublicCountStatistic>
<StatisticCode xmlns="Acc.StarPlus.XsdLib
<CategoryId>70</CategoryId
<CategoryValueId>2101</Cat
<DisplayCode>1</DisplayCod
<DisplayName>FOREIGN REVOKED CORPS </DisplayName>
<EnumName>FOREIGNREVOKEDCO
<IsActive>1</IsActive>
<SortOrder>1</SortOrder>
</StatisticCode>
<StatisticCount>10480</Sta
<StatisticDate>2009-12-31T
<StatisticType>CT</Statist
</PublicCountStatistic>
<PublicCountStatistic>
<StatisticCode xmlns="Acc.StarPlus.XsdLib
<CategoryId>70</CategoryId
<CategoryValueId>2102</Cat
<DisplayCode>2</DisplayCod
<DisplayName>DOMESTIC REVOKED CORPORATIONSDisplayName>
<EnumName>DOMESTICREVOKEDC
<IsActive>1</IsActive>
<SortOrder>1</SortOrder>
</StatisticCode>
<StatisticCount>6</Statist
<StatisticDate>2009-12-31T
<StatisticType>CT</Statist
</PublicCountStatistic>
<PublicCountStatistic>
<StatisticCode xmlns="Acc.StarPlus.XsdLib
<CategoryId>70</CategoryId
<CategoryValueId>2104</Cat
<DisplayCode>4</DisplayCod
<DisplayName>FOREIGN DELINQUENT CORPS<DisplayName>
<EnumName>FOREIGNDELINQUEN
<IsActive>1</IsActive>
<SortOrder>1</SortOrder>
</StatisticCode>
<StatisticCount>934</Stati
<StatisticDate>2009-12-31T
<StatisticType>CT</Statist
</PublicCountStatistic>
<PublicCountStatistic>
<StatisticCode xmlns="Acc.StarPlus.XsdLib
<CategoryId>70</CategoryId
<CategoryValueId>2105</Cat
<DisplayCode>5</DisplayCod
<DisplayName>DOMESTIC DELINQUENT CORPS </DisplayName>
<EnumName>DOMESTICDELINQUE
<IsActive>1</IsActive>
<SortOrder>1</SortOrder>
</StatisticCode>
<StatisticCount>4540</Stat
<StatisticDate>2009-12-31T
<StatisticType>CT</Statist
</PublicCountStatistic>
<PublicCountStatistic>
<StatisticCode xmlns="Acc.StarPlus.XsdLib
<CategoryId>70</CategoryId
<CategoryValueId>2106</Cat
<DisplayCode>6</DisplayCod
<DisplayName>FOREIGN CORPORATIONS</DisplayName>
<EnumName>FOREIGNCORPORATI
<IsActive>1</IsActive>
<SortOrder>1</SortOrder>
</StatisticCode>
<StatisticCount>58897</Sta
<StatisticDate>2009-12-31T
<StatisticType>CT</Statist
</PublicCountStatistic>
<PublicCountStatistic>
<StatisticCode xmlns="Acc.StarPlus.XsdLib
<CategoryId>70</CategoryId
<CategoryValueId>2107</Cat
<DisplayCode>7</DisplayCod
<DisplayName>DOMESTIC CORPORATIONS</DisplayName>
<EnumName>DOMESTICCORPORAT
<IsActive>1</IsActive>
<SortOrder>1</SortOrder>
</StatisticCode>
<StatisticCount>550861</St
<StatisticDate>2009-12-31T
<StatisticType>CT</Statist
</PublicCountStatistic>
<PublicCountStatistic>
<StatisticCode xmlns="Acc.StarPlus.XsdLib
<CategoryId>70</CategoryId
<CategoryValueId>2108</Cat
<DisplayCode>8</DisplayCod
<DisplayName>FOREIGN CORPORATIONS ADDED</DisplayName>
<EnumName>FOREIGNCORPORATI
<IsActive>1</IsActive>
<SortOrder>1</SortOrder>
</StatisticCode>
<StatisticCount>202</Stati
<StatisticDate>2009-12-31T
<StatisticType>MTH</Statis
</PublicCountStatistic>
<PublicCountStatistic>
<StatisticCode xmlns="Acc.StarPlus.XsdLib
<CategoryId>70</CategoryId
<CategoryValueId>2110</Cat
<DisplayCode>10</DisplayCo
<DisplayName>DOMESTIC CORPORATIONS REINSTATED</DisplayName>
<EnumName>DOMESTICCORPORAT
<IsActive>1</IsActive>
<SortOrder>1</SortOrder>
</StatisticCode>
<StatisticCount>225</Stati
<StatisticDate>2009-12-31T
<StatisticType>MTH</Statis
</PublicCountStatistic>
basically what i need to do here is : I need to write a LINQ query
To bind the above XML data to the datagrids in silverlight
For Statistic type CT, i need to bind the grid like below
BusinessCorporations Revoked Corps Delinquent Corps
Foreign 58897((i,e) ForeignCorporation 10480 934
Statistic code)
Domestic 550861 6 4540
Please i am new to LINQ, please help me to write a LINQ query to bind the above XML data to the datagrid like above
Thanks for your replies,
I am taking the XML data into a collection
The Row headers Foreign and Domestic are not there in the XML data
Ex: If from the XML StatisticCode.EnumName="Fo
Thanks,
ASKER
i have a data in a collection object taken from XML.
I need to format the data in such a way that...
from my xml. for PublicCountStatistics.Enum Name is ForeignCorporations, i need to display the StatisticCount of it
and for the DomesticCorporations, i need to display its StatisticCount like below
In the XML it will be written as DOMEsticCorporations and ForeignCorporations, but i will have a header in my grid called
Corporations which need to bind like below ... I even don't know how can i able to display the Foreign and Domestic as a Row header also.
Below is thr GRid
Corporations
FOReign 202
DOMESTIC 205
the below is the XML format.....
<PublicCountStatistic>
<StatisticCode xmlns="Acc.StarPlus.XsdLib rary">
<CategoryId>70</CategoryId >
<CategoryValueId>2108</Cat egoryValue Id>
<DisplayCode>8</DisplayCod e>
<DisplayName>FOREIGN CORPORATIONS </DisplayName>
<EnumName>FOREIGNCORPORATI ONS</EnumN ame>
<IsActive>1</IsActive>
<SortOrder>1</SortOrder>
</StatisticCode>
<StatisticCount>202</Stati sticCount>
<StatisticDate>2009-12-31T 00:00:00</ StatisticD ate>
<StatisticType>MTH</Statis ticType>
</PublicCountStatistic>
<PublicCountStatistic>
<StatisticCode xmlns="Acc.StarPlus.XsdLib rary">
<CategoryId>70</CategoryId >
<CategoryValueId>2108</Cat egoryValue Id>
<DisplayCode>8</DisplayCod e>
<DisplayName>DOMESTIC CORPORATIONS </DisplayName>
<EnumName>DOMESTICCORPORAT IONS</Enum Name>
<IsActive>1</IsActive>
<SortOrder>1</SortOrder>
</StatisticCode>
<StatisticCount>205</Stati sticCount>
<StatisticDate>2009-12-31T 00:00:00</ StatisticD ate>
<StatisticType>MTH</Statis ticType>
</PublicCountStatistic>
I hope you understood my issue, please help me with some code samples
Thanks
I need to format the data in such a way that...
from my xml. for PublicCountStatistics.Enum
and for the DomesticCorporations, i need to display its StatisticCount like below
In the XML it will be written as DOMEsticCorporations and ForeignCorporations, but i will have a header in my grid called
Corporations which need to bind like below ... I even don't know how can i able to display the Foreign and Domestic as a Row header also.
Below is thr GRid
Corporations
FOReign 202
DOMESTIC 205
the below is the XML format.....
<PublicCountStatistic>
<StatisticCode xmlns="Acc.StarPlus.XsdLib
<CategoryId>70</CategoryId
<CategoryValueId>2108</Cat
<DisplayCode>8</DisplayCod
<DisplayName>FOREIGN CORPORATIONS </DisplayName>
<EnumName>FOREIGNCORPORATI
<IsActive>1</IsActive>
<SortOrder>1</SortOrder>
</StatisticCode>
<StatisticCount>202</Stati
<StatisticDate>2009-12-31T
<StatisticType>MTH</Statis
</PublicCountStatistic>
<PublicCountStatistic>
<StatisticCode xmlns="Acc.StarPlus.XsdLib
<CategoryId>70</CategoryId
<CategoryValueId>2108</Cat
<DisplayCode>8</DisplayCod
<DisplayName>DOMESTIC CORPORATIONS </DisplayName>
<EnumName>DOMESTICCORPORAT
<IsActive>1</IsActive>
<SortOrder>1</SortOrder>
</StatisticCode>
<StatisticCount>205</Stati
<StatisticDate>2009-12-31T
<StatisticType>MTH</Statis
</PublicCountStatistic>
I hope you understood my issue, please help me with some code samples
Thanks
ASKER
My stored procedure return an XML llike below
<PublicCountStatistic>
<StatisticCode xmlns="Acc.StarPlus.XsdLib rary">
<CategoryId>70</CategoryId >
<CategoryValueId>2108</Cat egoryValue Id>
<DisplayCode>8</DisplayCod e>
<DisplayName>FOREIGN CORPORATIONS </DisplayName>
<EnumName>FOREIGNCORPORATI ONS</EnumN ame> <IsActive>1</IsActive>
<SortOrder>1</SortOrder>
</StatisticCode>
<StatisticCount>202</Stati sticCount>
<StatisticDate>2009-12-31T 00:00:00</ StatisticD ate>
<StatisticType>CUR</Statis ticType>
</PublicCountStatistic>
<PublicCountStatistic>
<StatisticCode xmlns="Acc.StarPlus.XsdLib rary">
<CategoryId>70</CategoryId >
<CategoryValueId>2108</Cat egoryValue Id>
<DisplayCode>8</DisplayCod e>
<DisplayName>DOMESTIC CORPORATIONS </DisplayName>
<EnumName>DOMESTICCORPORAT IONS</Enum Name>
<IsActive>1</IsActive>
<SortOrder>1</SortOrder>
</StatisticCode>
<StatisticCount>205</Stati sticCount>
<StatisticDate>2009-12-31T 00:00:00</ StatisticD ate>
<StatisticType>MTH</Statis ticType>
</PublicCountStatistic>
I wrote a method like below taking XML data in a collection
i have a class with set of properties like
public class PublicCountStatistic
{
public string RowHeader1
{
get;
set;
}
public int BusinessCorps
{
get;
set;
}
var pcs = from p in StatisticCount
where p.StatisticType.DisplayCod e == "CUR"
group p by new { p.StatisticType.DisplayCod e}
into pcsdata
select new PublicCountStatistic()
{
//EnumName = pcsdata.Key,
RowHeader1 = "Domestic"
BusinessCorps = pcsdata.Where(p => p.StatisticCode.EnumName == "DomesticBusinessCorporati ons").Sing leOrDefaul t().Statis ticCount,
};
List<PublicCountStatistic> publicCountStatistics = pcs.ToList();
dgCurrentStatisticsPart1.I temsSource = publicCountStatistics;
My silverlight Grid have the bindings like below
<data:DataGrid.Columns>
<data:DataGridTextColumn Header="" Binding="{Binding Path=RowHeader1}" />
<data:DataGridTextColumn Header="Business Corps" Binding="{Binding Path=BusinessCorps}"/>
</data:DataGrid.Columns>
and my output is like beliow
BusinessCoporations
Domestic 2108
But i need to get the output as Grid as
Business Corps
Domestic 2108
Foreign 205
How can i bind the Foreign corporations statisticcount also to the grid
what i code i need to add to the above, please help me on this...
<PublicCountStatistic>
<StatisticCode xmlns="Acc.StarPlus.XsdLib
<CategoryId>70</CategoryId
<CategoryValueId>2108</Cat
<DisplayCode>8</DisplayCod
<DisplayName>FOREIGN CORPORATIONS </DisplayName>
<EnumName>FOREIGNCORPORATI
<SortOrder>1</SortOrder>
</StatisticCode>
<StatisticCount>202</Stati
<StatisticDate>2009-12-31T
<StatisticType>CUR</Statis
</PublicCountStatistic>
<PublicCountStatistic>
<StatisticCode xmlns="Acc.StarPlus.XsdLib
<CategoryId>70</CategoryId
<CategoryValueId>2108</Cat
<DisplayCode>8</DisplayCod
<DisplayName>DOMESTIC CORPORATIONS </DisplayName>
<EnumName>DOMESTICCORPORAT
<IsActive>1</IsActive>
<SortOrder>1</SortOrder>
</StatisticCode>
<StatisticCount>205</Stati
<StatisticDate>2009-12-31T
<StatisticType>MTH</Statis
</PublicCountStatistic>
I wrote a method like below taking XML data in a collection
i have a class with set of properties like
public class PublicCountStatistic
{
public string RowHeader1
{
get;
set;
}
public int BusinessCorps
{
get;
set;
}
var pcs = from p in StatisticCount
where p.StatisticType.DisplayCod
group p by new { p.StatisticType.DisplayCod
into pcsdata
select new PublicCountStatistic()
{
//EnumName = pcsdata.Key,
RowHeader1 = "Domestic"
BusinessCorps = pcsdata.Where(p => p.StatisticCode.EnumName == "DomesticBusinessCorporati
};
List<PublicCountStatistic>
dgCurrentStatisticsPart1.I
My silverlight Grid have the bindings like below
<data:DataGrid.Columns>
<data:DataGridTextColumn Header="" Binding="{Binding Path=RowHeader1}" />
<data:DataGridTextColumn Header="Business Corps" Binding="{Binding Path=BusinessCorps}"/>
</data:DataGrid.Columns>
and my output is like beliow
BusinessCoporations
Domestic 2108
But i need to get the output as Grid as
Business Corps
Domestic 2108
Foreign 205
How can i bind the Foreign corporations statisticcount also to the grid
what i code i need to add to the above, please help me on this...
ASKER
Sorry.... i wrote the value wrong
and my output is like beliow
BusinessCoporations
Domestic 205
But i need to get the output as Grid as
Business Corps
Domestic 205
Foreign 202
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi ram27; Has my solution worked out for you?
Checking the status of the question. If it has been resolved please close the question.
Thank you.
Thank you.