Problem with Join and grouping
-
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
-
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
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