General purpose Record?

Jan 31, 2011 at 11:28 AM

Hi. I’m building an Image Gallery module and I need to persist some data related to the galleries/images that are belonging to a part yet. How can I persist data not related to a content item? I think cannot use ContentPartRecord since it has a direct relationship to ContentItemRecord.


Thanks in advance.

Coordinator
Jan 31, 2011 at 5:15 PM

You can use records and repositories without content types and parts. There's nothing magical there, just get an IRepository<SomeRecordType> and party on it. Of course, you'll need to create a migration to set-up the database table but that's it I think.

Jan 31, 2011 at 6:22 PM

You say my RecordClass doesn’t need to inherit from any other? When I invoke the Create method of IRepository<RecordClass> I get the following error:
No persister for: ImageGallery.Models.ImageGallerySettingsRecord.

Stack trace:
   at NHibernate.Impl.SessionFactoryImpl.GetEntityPersister(String entityName)   at NHibernate.Impl.SessionImpl.GetEntityPersister(String entityName, Object obj)   at NHibernate.Event.Default.AbstractSaveEventListener.SaveWithGeneratedId(Object entity, String entityName, Object anything, IEventSource source, Boolean requiresImmediateIdAccess)   at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event)   at NHibernate.Event.Default.DefaultSaveEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event)   at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.EntityIsTransient(SaveOrUpdateEvent event)   at NHibernate.Event.Default.DefaultSaveEventListener.PerformSaveOrUpdate(SaveOrUpdateEvent event)   at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.OnSaveOrUpdate(SaveOrUpdateEvent event)   at NHibernate.Impl.SessionImpl.FireSave(SaveOrUpdateEvent event)   at NHibernate.Impl.SessionImpl.Save(Object obj)   at Orchard.Data.Repository`1.Create(T entity) in d:\TeamCity\Projects\Orchard-1.x\src\Orchard\Data\Repository.cs:line 96   at Orchard.Data.Repository`1.Orchard.Data.IRepository<T>.Create(T entity) in d:\TeamCity\Projects\Orchard-1.x\src\Orchard\Data\Repository.cs:line 36   at ImageGallery.Services.ImageGalleryService.UpdateImageGalleryProperties(String imageGalleryName, Int32 thumbnailHeight, Int32 thumbnailWidth)   at ImageGallery.Controllers.AdminController.EditProperties(ImageGalleryEditPropertiesViewModel viewModel) 


And I think that I created the correct table for it. I don’t know, it seems to miss a Map-like class. Does it needs any call to ContentDefinitionManager on the migration for this purpose?

Thanks for the help.

Coordinator
Jan 31, 2011 at 6:52 PM

That's not what I said. Make the record derive from ContentPartRecord. I may be wrong on all this as I haven't tried it directly though.

Jan 31, 2011 at 7:00 PM

Thanks for your help. But that was my initial problem. If I take this approach I will end up with a "attempted to assign id from null one-to-one property: ContentItemRecord" 

This Record is not related to a Part itself. Think my controller is using a service that needs to persist some data on the database.

I am grateful for your attention.

Coordinator
Jan 31, 2011 at 7:03 PM

MMhh. Can I see the code for your migration?

Coordinator
Feb 1, 2011 at 1:50 AM

Something people have run into before: Orchard currently only recognize types are "Record" if they have a "public virtual int Id { get; set;}" property. And Orchard makes that property the ID of the table.

Feb 1, 2011 at 10:18 AM
rpaquay wrote:

Something people have run into before: Orchard currently only recognize types are "Record" if they have a "public virtual int Id { get; set;}" property. And Orchard makes that property the ID of the table.

You guys are brilliant! My Record class doesn't need to inherit from anything. Just added the virtual Id property and worked like a charm.

Soon I'll be contributing with a new module. Thank you very much!