ContentItemVersionRecord

Topics: Writing modules
May 16, 2012 at 8:21 PM

My module (non content item based) is hooking into the Orchard.Users module so that I can add Orchard Users to some of my tables.

When pulling out information for the Users, I came across an interesting and rather strange situation. I'm using the Contrib.Profile module to store additional information for the users such as First Name and Last Name. When I look at the ContentItemRecord table in the database, not all of the user items have this information in the Data column. For the ones that don't have the profile information in the Data column, I found it in the ContentItemVersionRecord table.

So...I have a couple of questions about this:

First, why is some of the data being written to one table and some to the other?

Second, I have code that is erroring out because it's looking for the data in the ContentItemRecord table and is coming back null since the data is in the ContentItemVersionRecord table:

@user.User.ContentItemRecord.Data.Substring(user.User.ContentItemRecord.Data.IndexOf("") + 11, user.User.ContentItemRecord.Data.IndexOf("") - user.User.ContentItemRecord.Data.IndexOf("") - 11)

user is an instance of a model that contains an Orchard User record.

Any ideas on how I can either make sure the Profile data is being written to ContentItemRecord...or how I can access ContentItemVersionRecord?

Thanks!

May 16, 2012 at 8:42 PM
Edited May 16, 2012 at 8:43 PM

I tried this and got it to work...so I guess I can go with this

 

@user.User.ContentItemRecord.Versions.LastOrDefault().Data.Substring(user.User.ContentItemRecord.Versions.LastOrDefault().Data.IndexOf("<FirstName>") + 11, user.User.ContentItemRecord.Versions.LastOrDefault().Data.IndexOf("</FirstName>") - user.User.ContentItemRecord.Versions.LastOrDefault().Data.IndexOf("<FirstName>") - 11)
Developer
May 16, 2012 at 9:16 PM
Edited May 16, 2012 at 9:16 PM

You could also use the IContentManager to query users. Then you don't have to interpret the records yourself and you'll be able to get at any custom fields easily.

 

Developer
May 17, 2012 at 6:21 PM

See this issue.

Also, my Helpful Libraries module contains extension methods for strongly-typed field access. You should either use that or a similar approach for accessing fields or you could cast the content part to dynamic and access the fields through Clay behaviours but frankly I've never tried that.