Pivot in C # entity framework 3.5

ISO Code description    Year    value
CAD Canadian Dollar     2009    1.3001
CAD Canadian Dollar     2010    1.3001
CAD Canadian Dollar     2011    0.0001
EUR Euro                2009    1.0000
EUR Euro                2010    1.0000
EUR Euro                2011    0.0001
USD US Dollar           2009    1.2300
USD US Dollar           2010    1.2300
USD US Dollar           2011    0.0001

Table 1

ISO Code    description 2009    2010    2011
CAD Canadian Dollar     1.3001  1.3001  0.0001
EUR Euro                1.0000  1.0000  0.0001
USD US Dollar           1.2300  1.2300  0.0001

table 2

How can I convert table 1 to table 2 using linq in C #, provided that the number of years is dynamic (it is not fixed in 2009,2010, 2011, values ​​2012,2013, and so on can be added later)

The classes are as follows:

class Currency
 {
    public string ISO Code { get; set; }
    public string Description { get; set; }
 }
class Rate
{        
    public string ISO Code { get; set; }
    public int Year { get; set; }
    public inr Value { get; set; }

}

In the end, I need to bind the results to a gridview. Someone can help

+3
source share
1 answer

I think this is not possible to do in Linq. Linq works with strongly typed objects, so your result should be strongly typed, but you say that this is not possible because other columns can be added over time (there is no dynamic behavior in .NET 3.5).

DataTable, SQL PIVOT (SQL Server 2005 ) .

SQL Server (SSRS 2005) Tablix (SSRS 2008).

Edit:

? "" . , :

var query = from c in ctx.Currencies.Include("Rates");

Rates .

+2

All Articles