score:6

Accepted answer

you have t and k around the wrong way (or vice versa)

new group<int, billperiodline>

...

public class group<t, k>
{
    public k key;
    public ienumerable<t> values;
}

cannot implicitly convert type 'int' to 'billtracker.entities.billperiodline'

the message says it perfectly, you are trying to push a square peg in a round hole

score:4

while michael randall's answer is perfectly sound regarding the error message, this is only part of the issue.

i guess that you'd like to display the grouped billperiodlines in some sort of table as shown in the link you provided. anyway, you can't simply return a list<billperiodline> and assume it to be grouped magically, neither can you create a list<billperiodline> from an ienumerable<group<int, billperiodline>> - which is the type of linesgrouped. presumably what you were trying to do, is to return a list<group<int, billperiod>>

public list<group<int, billperiodline>> getlinesgroupedbyperiod()
{
    var linesgrouped = _linerepository.allincluding(p => p.billperiod)
                                      .groupby(pl => pl.billperiodid)
                                      .select(g => new group<int, billperiodline>
                                      {
                                          key = g.key,
                                          values = g
                                      });
    return linesgrouped.tolist();
}

this list<group<int, billperiodline>> can be used from a view as shown in the example: the view is iterating over the list<group<int, billperiodline>>. for each group<int, billperiodline> it creates a header for the group and then iterates over all items in group<int,billperiodline>.values creating a line for each billperiodline.

furthermore (as michael stated) you'll have to swap the type parameters of your group<t,u> class (or switch the types where you create the group<int, billperiodline>, but i'd prefer the former, since i'd consider the key coming first a bit more intuitive).


Related Query

More Query from same tag