Developer forum

Forum » Development » Get Pages By Module Name

Get Pages By Module Name

D W
Reply

Hello,

We are working on a custom module and we need to be able to get ParagraphPageIDs from the Paragraph table where ParagraphModuleSystemName matches a passed in value.

How would this be done?

 

Thank you


Replies

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi D W,

 

You can do that with this query

SELECT ParagraphPageID FROM Paragraph WHERE ParagraphModuleSystemName = '{Your_Value_Here}'

 

Best Regards,

Nuno Aguiar

 
D W
Reply

We had the query figured out (that's how we knew the column names), but we were under the impression that the repo interface was the way to go.

 

How do you implement SQL queries like that in DW?

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply
This post has been marked as an answer

Hi D W,

 

Assuming you are using C# to build your custom module, you can do something like this:

 

var sqlCommandText = CommandBuilder.Create("YOUR QUERY HERE")
using (IDataReader dataReader = Dynamicweb.Data.Database.CreateDataReader(sqlCommandText))
{
  while (dataReader.Read())
  {
    // Your code here
  }
}

 

Best Regards,

Nuno Aguiar

Votes for this answer: 1
 
D W
Reply

Thank you. That worked for us (we had to play with it a little and for us it was Dynamicweb.Database, not Dynamicweb.Data.Database).

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Great, sorry about that. I was copy-pasting and typing some from memory. Glad you got it working

 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply

Another option is to use the API to get a subset of the cached paragraphs and take the page ids from there:

var pageIds = Dynamicweb.Services.Paragraphs.GetParagraphsByModuleName("MyModuleName").Select(paragraph => paragraph.PageID);

OR

var pages = Dynamicweb.Services.Paragraphs.GetParagraphsByModuleName("MyModuleName").Select(paragraph => paragraph.Page);

 

You must be logged in to post in the forum