I am trying to combine two tables. I want to find out how many products are underneath that category

Unal UN asked on January 2, 2018 11:43

Hi am using Kentico 10

I am trying to combine two tables. I want to find out how many products are underneath that category. Can you be a helper?

//Code Samples

 var result = CustomTableItemProvider.GetItems("customtable.MyJoinCategory").Source(s => s.LeftJoin("customtable_MyJoinProduct", "ItemID", "CategoyID")).Result;

Thank you

Recent Answers


David te Kloese answered on January 2, 2018 12:16

Hi,

just looking at the documentation I'd try adding the return type of CustomTableItem.

docs.kentico.com/k10/...Joiningmultipletables(SQLJOIN)

as in:

var result =
 CustomTableItemProvider.GetItems("customtable.MyJoinCategory")
.Source(s => s.LeftJoin<CustomTableItem>
  ("customtable_MyJoinProduct", "ItemID", "CategoyID"))
.Result;

But it might also fail because of the ItemID column, as probably both your custom tables have this column.

So you might want to include the table name:

var result =
 CustomTableItemProvider.GetItems("customtable.MyJoinCategory")
.Source(s => s.LeftJoin<CustomTableItem>
  ("customtable_MyJoinProduct", "customtable_MyJoinProduct.ItemID", "CategoyID"))
.Result;
0 votesVote for this answer Mark as a Correct answer

Unal UN answered on January 2, 2018 12:21 (last edited on January 2, 2018 12:21)

Hi David,

I can combine two tables. I can not find the total number of products under the category.

Samples

Category1 => Product 4 Count, Category2 => Product 2 Count, Category3 => Product 0 Count,

Thank you

0 votesVote for this answer Mark as a Correct answer

David te Kloese answered on January 2, 2018 14:28

In the query article is mentioned how to add a count column:

     .AddColumn(
         new CountColumn("CustomColunmnXYZ").As("ColunmnCount")
     )

https://devnet.kentico.com/articles/kentico-8-technology-dataquery-api

I think this should return the counters you need.

0 votesVote for this answer Mark as a Correct answer

Unal UN answered on January 3, 2018 08:39

Hİ David

sorry, I did not understand.

var result = CustomTableItemProvider.GetItems("customtable.MyJoinCategory").Source(s => s.LeftJoin("customtable_MyJoinProduct", "ItemID", "CategoyID")).Result;

?

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.