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
  1. Home
  2. General Programming
  3. LINQ
  4. Problem with Join and grouping

Problem with Join and grouping

Scheduled Pinned Locked Moved LINQ
helpdatabasecsharplinqsales
2 Posts 1 Posters 0 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.
  • T Offline
    T Offline
    TAK78
    wrote on last edited by
    #1

    I just started working with Linq a few days ago and I'm coming across a problem which gives me a hard time. I already searched many code samples online but I'm still having problems. I have two tables which are linked through material. I try to collect certain columns from each table of each material and than group the materials together which have the same picture. Here is one of the code samples I tried but it gives error on mg: (Definition of method mg is not accessible in this context) Dim db As New ZTDataDataContext Dim prod = From m In db.ProductSpecs Join v In db.ProductVerbages On m.material Equals v.material _ Where m.subclass.Contains(ViewState("matcat")) Group m By m.product_photo Into mg _ Select New Product With {.Material = m.material, _ .MarketingTagline = v.marketing_tagline, .IDKey = m.idkey, .ProductPhoto = m.product_photo} I'm not sure how I can get them into the group mg and than select all the other data. Would I need to create two query's or could I do it in one? Any help and explanation is very appreciated! Thanks Thomas

    T 1 Reply Last reply
    0
    • T TAK78

      I just started working with Linq a few days ago and I'm coming across a problem which gives me a hard time. I already searched many code samples online but I'm still having problems. I have two tables which are linked through material. I try to collect certain columns from each table of each material and than group the materials together which have the same picture. Here is one of the code samples I tried but it gives error on mg: (Definition of method mg is not accessible in this context) Dim db As New ZTDataDataContext Dim prod = From m In db.ProductSpecs Join v In db.ProductVerbages On m.material Equals v.material _ Where m.subclass.Contains(ViewState("matcat")) Group m By m.product_photo Into mg _ Select New Product With {.Material = m.material, _ .MarketingTagline = v.marketing_tagline, .IDKey = m.idkey, .ProductPhoto = m.product_photo} I'm not sure how I can get them into the group mg and than select all the other data. Would I need to create two query's or could I do it in one? Any help and explanation is very appreciated! Thanks Thomas

      T Offline
      T Offline
      TAK78
      wrote on last edited by
      #2

      I got it to group now but I have trouble when trying to bind it to a Datalist Protected Sub LinqDataSource1_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LinqDataSourceSelectEventArgs) Handles LinqDataSource1.Selecting Dim prod = From x In (From m In db.ProductSpecs Join v In db.ProductVerbages On m.material Equals v.material _ Where m.subclass.Contains(ViewState("matcat")) _ Select New Product With {.Material = m.material, .MarketingTagline = v.marketing_tagline, .IDKey = m.idkey, .ProductPhoto = m.product_photo}) _ Group x By x.ProductPhoto Into mg = Group _ Select mg Dim pl As New List(Of Product) For Each item In prod.ToArray() pl = item.ToList 'MsgBox(item.ToString) 'For Each x In item.ToArray ' MsgBox(x.ProductPhoto) 'Next Next e.Result = pl End Sub Code for Datalist: <asp:DataList ID="DataList1" DataSourceID="LinqDataSource1" runat="server" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" ForeColor="Black" GridLines="Vertical"> <FooterStyle BackColor="#CCCCCC" /> <SelectedItemStyle BackColor="#000099" Font-Bold="True" ForeColor="White" /> <ItemTemplate> <table> <tr> <td style="width:100px; font-weight:bold;"> <asp:ImageButton ID="Image1" Width="40" runat="server" ImageUrl='<%# "~/Images/ProductImages/" + Eval("ProductPhoto").toString() %>' /> <asp:Label ID="materialLabel" runat="server" Text='<%# Eval("Material") %>' /> </td> <td style="width:370px; padding-left: 5px; text-align: left;"> <asp:Label ID="Label" runat="server" TabIndex="1" Text='<%# Eval("MarketingTagline") %>' /> </td> <td style="width:80px; text-align:center;"> <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("Material", "dataSheet.asp

      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