This project is read-only.

Programmatically create Binding, Query and Projection in Orchard CMS

Topics: Writing modules
Oct 13, 2012 at 6:28 PM
Edited Oct 13, 2012 at 6:28 PM


I wrote module for Orchard CMS, and I need to have many (about 120) Projections, filtered by fields in my ContentType. From web interface, I can do it by: create Binding, create Qurery based on Binding, create Projection based on Query. But I need do it programmatically.

 I suppose, that it's really to do it from database. Which tables I need add records to create projection? Or there is another way to solve this problem?

Thank you!

Oct 13, 2012 at 6:53 PM

This number sounds suspicious? Don't these projections have anything in common? Are we talking about queries or projections? If you can build them programmatically, why can't you build a custom filter or something that makes it based on a parameter rather than generated?

In any case, projections are just content items so you can create them through the content manager. Never try to write to the tables directly, you'll only succeed in corrupting your database.

Oct 13, 2012 at 7:02 PM

I try to create web market market based on Orchard. I have CSV-file with products. I wrote simple utility to import products into my Content Type. In my utility, I read row from file and write it to MarketPartRecord (table of my module), Orchard_Framework_ContentItemRecord, Orchard_Framework_ContentItemVersionRecord, Common_CommonPartRecord, Common_CommonPartVersionRecord.

I need update information programmatically, and I do it via LINQ. Projections will be lists of products sorted by categories. I need create it programmatically.

Oct 13, 2012 at 7:06 PM

Why don't you have one projection, with a category parameter? It seems completely absurd to create a new projection every time you add a category.

Oct 13, 2012 at 7:12 PM

I need create menu with hierarchical structure, and each category should be page. I don't understand you, how can I do it with only one projection? Sorry for my stupid question.

Oct 13, 2012 at 7:34 PM

Projections can take filters, which can have parameters and settings.

In any case, it seems like you could do something even simpler by using taxonomies, which already have support for insertion into Orchard's hierarchical menu.

Oct 13, 2012 at 9:29 PM

thank you!

Oct 13, 2012 at 9:29 PM

thank you!

Oct 26, 2015 at 12:50 AM

Even though for the original poster it turned out to be a non issue, I would like to know how it is possible to add Query Bindings and build a query programmatically.

I'm creating a customization (a module + some prepackaged features) that requieres me to create a set of queries for projections. I would preffer if i can script that in some way either through a recipe or through migration.

I have a custom part that has several record properties. I can add query binding via the UI and use them in the query, but i can not figure out how to do it in code or in the recipe.