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. Visual Basic
  4. entity framework Group by multiple columns and count the number of groups with more than 1 item

entity framework Group by multiple columns and count the number of groups with more than 1 item

Scheduled Pinned Locked Moved Visual Basic
questiondatabase
2 Posts 2 Posters 1 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.
  • D Offline
    D Offline
    desanti
    wrote on last edited by
    #1

    Hello ! I'm using Entity Framework 6 I have Myobject1 : Name , City , Price, Value I want to group all the items on groups that have the same Name , city and Price. After I want to count the groups that have more than 1 item. I'm using this code :

    Dim q As Integer = context.myobjects.GroupBy(Function(x) New With {x.Name,x.City,x.Price}).Where(Function(t3) t3.Count > 1).Count

    But this query always return 0 But on my table I have several groups that have more than 1 item. What is wrong with my query ? Thank you !

    Richard DeemingR 1 Reply Last reply
    0
    • D desanti

      Hello ! I'm using Entity Framework 6 I have Myobject1 : Name , City , Price, Value I want to group all the items on groups that have the same Name , city and Price. After I want to count the groups that have more than 1 item. I'm using this code :

      Dim q As Integer = context.myobjects.GroupBy(Function(x) New With {x.Name,x.City,x.Price}).Where(Function(t3) t3.Count > 1).Count

      But this query always return 0 But on my table I have several groups that have more than 1 item. What is wrong with my query ? Thank you !

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      That code looks like it should work. Are you sure you're connecting to the right database? What happens if you run the generated query directly within SQL? You can see the query with:

      Dim query As String = context.myobjects.GroupBy(Function(x) New With {x.Name,x.City,x.Price}).Where(Function(t3) t3.Count > 1).ToString()


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      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