This project is read-only.

Using data from other systems.

Feb 1, 2011 at 4:35 PM
Edited Feb 1, 2011 at 4:49 PM

I am considering which CMS to use for my eCommerce platform, to do this I am playing with orchard to see if I could make it fit....

I am following the tutorials to create a ContentPartRecord called Product which has SKU, Price etc. However I also want it to have a reference to a 'unit of measure' which is in a seperate accounting system.

Am I able to write my own implementation of the IRepository to allow me to load this via EntityFramework? How would this work during editing?

Would I be able to do something like:


But where would I put this in my Module? Could I share this between multiple modules that share this dependancy?

Orchard looks great, but a bit of help would be nice to get me up and running quickly.

Many Thanks.

Edit: I copied DataModule from Orchard.Framework.Data and did this:


This seems to send an ExternalRepository<Foo> into my FooHandler when I request an IRepository<Foo>.

I am going to see if I can get Orchard to read/write content parts through this interface.

Feb 1, 2011 at 7:37 PM

Concerning your question about dependencies and sharing them across modules, I think you found the solution: Define an "autofac module" (autofac module != orchard module) registration class and inject your dependency. As for sharing between modules, you probably want to make sure specify dependencies in your "Module.txt" file as this would ensure your module doing the registration is enabled and active when you enable other modules depending on it.

Concerning customizing IRepository, this is an interesting approach to the problem. I'd be curious to see if you can get it to work this way, it would be awesome. That said, if i understand properly your scenario, you don't really need to have a specific repository implementation. You could just have a content handler that instantiates a "LazyField" in your part, and that "LazyField" would handle retrieving the data from an external source (and you could use EF directly there I suppose). The other issue to figure out is transactions of course.

Note that this would only work if Orchard does have the list of content items in its own database (e.g. i'm assuming you followed the tutorial and that your "Products" are content items). If you need to have everything in a separate back-end, it gets more tricky (because Orchard currently really needs content item IDs from its own ContentItem record table). In that case, what we have seen (for the Orchard Gallery for example) is people creating an Orchard background tasks that can read from a "log" table/service provided by the back end, and ensure content items (Ids) are in sync with the back-end.




Feb 1, 2011 at 8:16 PM

Hi Renaud,

  Thanks very much for your response, I am doing this the way you have suggested, but I have come up against a problem. Here is the class I am using to test with:

   public class AddressPartRecord : ContentPartRecord
        public virtual string Address { get; set; }
        public virtual StateRecord StateRecord { get; set; }
        public Uom Uom { get; set; }

   (I am using the 1-n tutorial). The StateRecord stuff all works fine, so I assumed I would be able to simply present an IRepository<Uom> and it would all be happy, however I get the following error from NHibernate:

  "An association from the table default_Maps_AddressPartRecord refers to an unmapped class: MyNamespace.Entities.Uom"

  This is why i removed the 'virtual' keyword from the definition - to no avail.

   Is there anyway of getting round this problem? I have no experience with NHibernate, and I originally assumed it would use the generic IRepository<Uom> to deal with this data, but now I see that is an Orchard class, and so there must be a deeper connection here. Is there an attribute or something I can use to correct this? I have added Uom_Id in the database in the same manor as StateRecord_Id, if I were to use a different convention on this name would NHibernate ignore this relationship?

An association from the table default_Maps_AddressPartRecord refers to an unmapped class: Ocl.Business.Entities.Uom

Feb 1, 2011 at 8:39 PM

Ah I see...

Hmm, i don't think this approach is going to work: NHibernate needs to understand all the types you are using (including Uom in this case), and they need to be mapped to a table AFAIK. IRepository<T> is an Orchard concept built on top of NHibernate, so NHib won't know that Uom persistance is handled by IRepository<T>.

I think i'd try something like this instead:

public class AddressPartRecord : ContentPartRecord
        public virtual string Address { get; set; }
        public virtual StateRecord StateRecord { get; set; }
        public virtual int UomId { get; set; }

public class AddressPart : ContentPart<AddressPartRecord>
        public string Address { get { return Record.Address;} }
        public StateRecord StateRecord { get { return Record.StateRecord;} }
        public LazyField<Uom> UomField { get; set; }
        public Uom Uom { get { return UomField.Value; } set { UomField.Value = value;} }

then write a AddressPartHandler handler that hooks up UomField UomId of the AddressPartRecord table (using EF I suppose). There are examples of using LazyField in a few Orchard modules, I believe..

The thing that is still not clear to me is transaction management. I don't know how i would go about coordinating the changes to "Uom" and "AddressPartRecord". Is "Uom" writable, or is it just a "read-only" reference table?


Feb 1, 2011 at 9:31 PM

Hi Renaud,

   Yes I think your right. I will have to abandon that. But referencing it in the ContentPart is fine. I have not seen your LazyField stuff - I will have to take a look.

   There will be no changes to Uom via referencing entities. So there is not really a great need to have it Object referenced, ID is fine. The only thing it will be used for is Display, apart from in the external system where it is used properly. Of course it wont be on an Address, but a Product!

    I want to be able to update Uom and other entities inside Orchard, but weather I do this via IRepository or some other mechanism I have yet to see... I've only downloaded Orchard today.

   Thank you very much for your help - I'll let you know how I get on.


Jun 13, 2011 at 8:43 AM

Hi, i have basicly the same question:

I have an external dataservice dll and want to load data from that dll within a module service. Is this possible or do i really have to do this in an parthandler?


Jun 13, 2011 at 2:49 PM

You can access it from anywhere you like. You'd do it from a part handler or driver if that data needed displaying as part of a content item or widget.