Rich Object from other database, as ContentPartRecord?

Topics: Core, General
Jun 5, 2013 at 8:48 AM
Hi all,

I am evaluating Orchard for an application. Can I find out from you who are experience in Orchard, whether the following is possible in Orchard?

There is an tutorial example in
http://docs.orchardproject.net/Documentation/Creating-a-module-with-a-simple-text-editor

public class ProductPartRecord : ContentPartRecord {
public virtual string Sku { get; set; }
public virtual float Price { get; set; }
}

As I guessed, the ProductPartRecord will be persisted into Orchard database. Can I have a complex Class as record, and the record are persisted through other library, and persisted in other database?

public class PublicationTopicRecord: ContentPartRecord {
public virtual OtherLibrary.PublicationTopic PublicationTopic;
}


Thanks.
Tien Huat
Jun 5, 2013 at 11:47 AM
Edited Jun 5, 2013 at 11:49 AM
You can have a complex class (that represents relations) as a record but not one that extends its reach to another database. There is just no way for it to work out the association.

you can populate a Part with data from another database source, including making it lazy load.
You may need to suppress the session to access the other datasource though as follows:
using (new TransactionScope(TransactionScopeOption.Suppress)) {
    // var product = externalDatabase.Products.Single(e=> e.id == part.ProductId); //store product id in the part record or go by sku 
    // myPart.Sku = product.Sku;
    // myPart.Price = product.Price; 
}
Adding this to the ContentHandler would be a good place to get the data during one of the events like OnLoaded. This will lead to lots of single queries for data though. Other strategies could be implemented to improve the performance though.

Ie you could run a service which copies the price of the over from the main database and checks every nth minute or so for modifications.