Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. LINQ
  4. Problem when using group by

Problem when using group by

Scheduled Pinned Locked Moved LINQ
csharplinqhelp
2 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    linqabc
    wrote on last edited by
    #1

    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

    A 1 Reply Last reply
    0
    • L linqabc

      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

      A Offline
      A Offline
      Andreas X
      wrote on last edited by
      #2

      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 and from 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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups