This project is read-only.

Data Access from a Module

Topics: Writing modules
Feb 22, 2011 at 3:51 AM


In my Orchard application, I am interested in maintaining some data and based on a query only a portion of that data will be returned back (like where clause in SQL). It is like carrying out database operations with SQL.

How can I do it? It would be great if anyone let me know some details on how to do it.


Feb 22, 2011 at 4:03 AM

You can do that in many different ways. What does that data look like?

Feb 22, 2011 at 4:47 AM

It contains individual information, I need to extract them based on country, organisation, age etc. e.g. Extract individuals below 30.  And also need to add data (no need of editting)...

Can I create a DB in the Orchard project it self and work.. or is there any better way???


Feb 22, 2011 at 5:14 AM

Are there reasons to integrate that dta with the rest of Orchard? For example, do you need to add comments, tags or any of that sort of reusable parts? If so, you should make a content part and type (following one of the tutorials on the documentation site). Otherwise, you can just create a record class (with an id), a migration that determines how that record should be stored in the database, and you'll then be able to inject a repository of the record from anywhere (such asa controller) and use it to query any way you want. For that you can look at a somewhat similar example inside of this module:

Feb 22, 2011 at 5:27 AM

Thanks a lot.. I will look into that module... Thanks again..

Feb 22, 2011 at 6:43 AM

I took some time to blog this:

Feb 22, 2011 at 10:56 AM


I checked the link you provided. But that module is not working and thus, not possible to run.

I am new to Orchard. I tried the tutorial to create the Orchard.commerce it gives errors.. :(

Also I tried to create a new database, but at the compilation (when visited the particular page) it says connection cannot be made.

Can u kindly provide me a detail description on how to do it.. pls...

Should I use a webservice???


Feb 22, 2011 at 4:42 PM
Edited Feb 22, 2011 at 4:44 PM

I would suggest to look at Creating a Module like the map Module here:


Your db will be created via the migration file.  Key word is Migration.

Feb 22, 2011 at 7:57 PM

What do you mean it doesn't work? What steps did you follow to install it? What happens when you try? Are you seeing an error message? What error message?

Where is that Orchard.Commerce tutorial you are talking about? Is it this one?

What errors does it give?

When you say you tried to create a new database, how exactly did you do that? How are you trying to access it and what exact error message are you seeing?

Apr 22, 2011 at 8:54 AM


I have created two tables for data in my module and done migration properly. One table will contain configuration details of my module when added to a content type and i have no problem with it.

When the module is added to some content type(eg Page), the user will be able to comment on each content item created seperately(regarding the stuff from module). I use the second table to store these data, but couldn't figure out how it is done even after following themepicker module :-/

Any place i can get some help??

Apr 22, 2011 at 12:13 PM

Have you seen the documention on 1-n and n-n relationships:

That should give you a good start.

Apr 22, 2011 at 9:24 PM

That doesnt have Any support on how to add data from other than the admin panel...

Apr 23, 2011 at 12:51 PM

Yes it does; IRepository<StateRecord> ...