This project is read-only.

Creating content items in migrations.cs

Topics: Customizing Orchard, Writing modules
Jun 8, 2012 at 10:31 AM

Hello, I would like to ask, if there is a way how to create content items when activating a module. (Possibly in the migration part).

Suggested scenario is that my Custom module depends on Projections and queries and needs to create a standard set of queries on activation?

Is a scenario like this possible?



Jun 8, 2012 at 12:22 PM

Absolutely, just inject the IContentManager in your migration class and any other service you need and use them to create content.

Jul 4, 2012 at 1:40 PM


I'm also looking for a way to create queries and projections via migration, how did you solve it and can you paste the code you are using from your migration class?

That would be a great help to me!


Jul 10, 2012 at 2:29 PM

Our approach is based on IFeatureEventHandler, we create content when a feature is enabled.


       void IFeatureEventHandler.Enabled(Feature feature)
            if (feature.Descriptor.Name == "yourFeature")
                //programmatically create content

Jul 10, 2012 at 8:15 PM


This is exactly what I'm looking for! Do you know how to programmatically create a query and projection? And how do you set that up in the migration?