Query Many to Many relationship between ___Info classes

L B asked on February 28, 2019 07:33

Hi,

Kentico version: 12.

We end in a tricky situation for a new site module and maybe we miss something here.

Short version: We try to make a query to load an Info object from an InfoProvider that have children other Info object, is there a way to get the children as a list without having to make a Join query and then foreach the data manually to group them ?

Note: We did follow all the instruction here https://docs.kentico.com/k12/custom-development/creating-custom-modules/creating-custom-binding-classes but it explains how to setup not how to query with the info provider

Long version: We created a module and we have 3 Main Info classes, A, B, C.

A: [Id], [Name] B: [Id], [Name] C: [Id], [Name]

Now we have 2 other Info class X and Y that are used to manage the many to many relationship between them: X: [A.Id], [B.Id] Y: [A.Id], [C.Id]

So A have B and C objects has children, really a classic structure...

In Entity Framework it would be quite simple to query that by just having 2 virtual Properties on A defining the relationship and it would load the children automatically into A, something like that:

public virtual List<B> bChildren {get; set;}

public virtual List<C> cChildren {get; set;}

Is it possible to query A with Kentico that loads the sub objects, or define something that will make it load these objects.

The only way I see after reading the documentation right now would be either to Left join and merge the data in the code or make 3 query and merge the data in the code too.

As it is pretty standard I hope there is something a bit better than foreach the data...

Thanks.

Correct Answer

L B answered on March 3, 2019 23:13

So the answer is on a 3 years old article. There is a .Children dictionary that can do the trick if it is setup properly, read Macro part.

https://devnet.kentico.com/articles/module-development-parent-child-relationships

0 votesVote for this answer Unmark Correct answer

Recent Answers


L B answered on March 2, 2019 01:15

These are barely related to the question... it just have many to many in the name.

0 votesVote for this answer Mark as a Correct answer

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