score:6
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 billperiodline
s 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).
Source: stackoverflow.com
Related Query
- Grouping Data with LINQ Not Working
- Grouping data with Linq or not possible?
- Linq Code with Distinct or GroupBy not working
- Update data with LinQ to SQL not working
- Distinct not working with LINQ to Objects
- Distinct not working with LINQ
- VB.NET linq group by with anonymous types not working as expected
- LINQ Lambda query 'select' not working with oData
- LINQ Grouping by custom type not working
- LINQ grouping and aggregating data with conditions
- Add a LINQ or DBContext extension method to get an element if not exist then create with data in predicate (FirstOrCreate)
- String.StartsWith not working with tilde ("~") characters LINQ to SQL?
- Using delete on a LINQ to Sql Data Context with an Interface - 'Interface is not mapped as a table'
- Outer join with linq query in EF Core 3 not working
- Linq statement with mutiple OrderBy clauses not working
- Grouping data with a LINQ query
- Linq to sql as object data source - designer problem with partial classes
- LINQ with Where and All not filtering data - What is wrong with this query?
- How to swap the data source associated with a Linq query?
- VB.NET linq extension methods such as ToList not working with generics
- User Defined Table Type not working with Linq
- Grouping hierarchical data with LINQ
- SQL to LINQ Query with date in where clause is not working
- Linq with null parameters not working
- Regex is not working with Linq to Sql
- Linq code not working properly
- Linq with data Error condition ( 'Date' is not supported in LINQ)
- EF Core 5.0 Union Linq Query with sub selects not working
- Linq is not working with sitecore solr
- Linq select with filtering not working
More Query from same tag
- LINQ: why does this query not work on an ArrayList?
- OrderBy list LINQ Query
- Update the list object
- Is it possible to implement RemoveAll() on EntityCollection<T>?
- c# Merging 3 collection list into one list
- Set up self referencing class
- linq condition to accept null dictionary(Value) if not passed by treating it as null
- How to Select Multiple Fields from DataGridView using LINQ in C# WinForms
- Having 3 where clauses in LINQ
- set DataSource for DataGridView
- Retrieve records from the database matching multiple values of a list
- How do I return list of elements by attribute value
- Is there any Operator "LIKE" in the Observable Collection for filetring
- MongoDB : Update only those objects in a collection whose 'Id' exists in a list
- Data bind ObservableCollection<XElement> to a ListBox?
- Operand data type time is invalid for add operator
- What is the best way to transparently log changes to objects when using LINQ-to-SQL?
- Calling DB Function with Entity Framework 6
- Comparing OffSetDateTime's Date part with Today in EF/Linq with NodaTime
- Using a Query Object In A C# Expression to Return A different type
- How would I create a dynamic total on field name in C#?
- Why is my result of type List<IEnumerable<T>>
- Get Values from single column based on condition
- LINQ select using .split()
- CompilationErrorException when including System.Linq in Roslyn CP2
- Cast exception of nested class in Linq query
- Linq return all columns from all tables in the join
- Populate a selected list from another selected list in one View
- LINQ to SQL - How to efficiently do either an AND or an OR search for multiple criteria
- How to convert a passing string paramatre to int on asp.net MVC 3