linq - How to take X elements from a group by in C# lambda -


i want take last 4 elements groupby , add list. i'm using mysql database , asp mvc5. tried this:

list<payments> payments= db.payments     .where(e => e.account.active==true)     .groupby(e => e.idaccount)     .select(e => e.orderby(x => x.paiddate).take(4))     .selectmany(e => e).tolist(); 

i got following error:

unknown column 'join2.idaccount' in 'where clause'

this payment class:

public partial class payment {     public int id { get; set; }      [foreignkey("account")]     [displayname("id account")]     public int idaccount { get; set; }      [foreignkey("client")]     [displayname("id client")]     public int idclient { get; set; }      public nullable<decimal> amount { get; set; }      [displayname("paid date")]     public system.datetime paiddate { get; set; }       public virtual account account { get; set; }     public virtual client client { get; set; } } 

could it's mysql provider (sql expression creator) error. but, have tried way?

list<payments> payments = db.payments     .where(e => e.account.active == true)     .groupby(e => e.idaccount)     .select(e => e.orderby(x => x.paiddate))     .take(4)     .selectmany(e => e).tolist(); 

if doesn't you, can pass query code way:

list<payments> payments = db.payments     .where(e => e.account.active == true)     .groupby(e => e.idaccount)     .tolist() // here calculations on web server, not in sql. sql query simlier     .select(e => e.orderby(x => x.paiddate))     .take(4)     .selectmany(e => e).tolist(); 

but, affect perfomance.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -