Problem when using group by
-
i want to select id ,name,code,sum(deposit) groupby name the code var b = from a in DBContext.ctx.RestrictionsDetails_Views where (a.Relay == true) && (a.ID == grpID) && (a.Restric_Date < DateTime.Parse(dedit_from.Text)) group a by a.Account_Name into g select new { name= g.Key, Account_ID = (from o in g select o.Account_ID, Account_code = from o in g select o.Account_code.Value, RestricDet_Deposit = g.Sum(x =>x.RestricDet_Deposit) }; the result is name RestricDet_Deposit name1 200 Account_ID and Account_code dislayed System.Data.Linq.SqlClient.Implementation.ObjectMaterializer`1+<Convert>d__0`1[System.Data.SqlClient.SqlDataReader,System.Nullable`1[System.Int32]] it doesn't display value
-
i want to select id ,name,code,sum(deposit) groupby name the code var b = from a in DBContext.ctx.RestrictionsDetails_Views where (a.Relay == true) && (a.ID == grpID) && (a.Restric_Date < DateTime.Parse(dedit_from.Text)) group a by a.Account_Name into g select new { name= g.Key, Account_ID = (from o in g select o.Account_ID, Account_code = from o in g select o.Account_code.Value, RestricDet_Deposit = g.Sum(x =>x.RestricDet_Deposit) }; the result is name RestricDet_Deposit name1 200 Account_ID and Account_code dislayed System.Data.Linq.SqlClient.Implementation.ObjectMaterializer`1+<Convert>d__0`1[System.Data.SqlClient.SqlDataReader,System.Nullable`1[System.Int32]] it doesn't display value
I don't really get your problem. But with the query given you will get lists from the subquerys
from o in g select o.Account_ID
andfrom o in g select o.Account_code.Value
you should select like First() (i suppose the Account_ID is the same for all account with the same name, and the same for the Account_code)(from o in g select o.Account_ID).First()
and(from o in g select o.Account_code.Value).First()
Andreas Johansson
IT Professional at Office IT Partner i Norrbotten Sweden
What we don't know. We learn.
What you don't know. We teach