UpdateFrom1 Filled table

Topics: Customizing Orchard
Jun 1, 2013 at 8:19 AM
Edited Jun 1, 2013 at 8:22 AM
Hi,

I am based my work on this tutorial, I have a book and to a book I associate an author and a category.

I use the script migration, create works, update there is an error.
I have all completed fields.
I add a column Id because I obtain the same issue without this colulmn, and I thought it was the reason, but I was wrong.
Resharper proposes when I add an id column to add the keyword new. So I did.
but not solves the issue. The issue occurs when the author record is created.

The Orchard.Data.Repository says it's wrong.
       public virtual void Create(T entity) {
            Logger.Debug("Create {0}", entity);
            Session.Save(entity);
        }
not-null property references a null or transient value

entity  {CoinLecturePck.Models.AuthorBookRecord}    CoinLecturePck.Models.AuthorBookRecord
base    {CoinLecturePck.Models.AuthorBookRecord}    Orchard.ContentManagement.Records.ContentPartRecord {CoinLecturePck.Models.AuthorBookRecord}
Description "test"  string
Firstname   "Stephen"   string
Id  0   int
Lastname    "King"  string
In the update method I populate a list with authorBook element
      private readonly IEnumerable<AuthorBookRecord> _authorBook =
            new List<AuthorBookRecord> {
                new AuthorBookRecord {Description = "test", Firstname = "Stephen", Lastname="King"},
                new AuthorBookRecord {Description = "test", Firstname = "Dean", Lastname = "Koontz"},
                new AuthorBookRecord {Description = "test", Firstname = "Anne", Lastname = "Rice"}
            };

public int UpdateFrom1()
        {
            if (_authorRepository == null) throw new InvalidOperationException("Couldn't find authorRepository.");
            if (_authorBook != null)
            {
                foreach (var author in _authorBook)
                {
                    _authorRepository.Create(author);
                }
            }
            return 2;
        }
 public class AuthorBookRecord : ContentPartRecord
    {
        public new virtual int Id { get; set; }
        public virtual String Firstname { get; set; }
        public virtual String Lastname { get; set; }
        public virtual String Description { get; set; }       
    }

    public class AuthorBookPart : ContentPart<AuthorBookRecord>
    {
        public new int Id {
            get { return Record.Id; }
            set { Record.Id = value; }
        }

        public String Firstname
        {
            get { return Record.Firstname; }
            set { Record.Firstname = value; }
        }

        public String Lastname
        {
            get { return Record.Lastname; }
            set { Record.Lastname = value; }
        }

        public String Description
        {
            get { return Record.Description; }
            set { Record.Description = value; }
        }       
    }
http://docs.orchardproject.net/Documentation/Creating-1-n-and-n-n-relations
Developer
Jun 1, 2013 at 10:58 AM
Your AuthorBookRecord subclasses ContentPartRecord, which has an Id property itself, so you should definitely not create an Id property on the AuthorBookRecord class.

Question: since AuthorBookRecord is a ContentPartRecord and part of a content part, why are you creating AuthorBookRecord instances directly, instead of using the content manager? I don't think content parts can live on their own without being part of a content item.
Jun 1, 2013 at 12:02 PM
Edited Jun 1, 2013 at 12:26 PM
Hum
Ok I remove the id.

I still obtain the same issue.
not-null property references a null or transient value.

So to be sure everything is clear I add a method in migration class
        public int UpdateFrom2() {
            DeleteAllTables();
            FillTables();
            return 3;
        }
private void FillTables() {
            if (_authorRepository == null) throw new InvalidOperationException("Couldn't find authorRepository.");
            if (_authorBook != null)
            {
                foreach (var author in _authorBook)
                {
                    _authorRepository.Create(author);
                }
            }

            if (_bookCategoryRepository == null) throw new InvalidOperationException("Couldn't find bookRepository.");
            if (_categoryBook != null)
            {
                foreach (var categorieBook in _categoryBook)
                {
                    _bookCategoryRepository.Create(categorieBook);
                }
            }
        }

        private void  DeleteAllTables(){
            try {
                SchemaBuilder.DropTable("AuthorBookRecord");
                SchemaBuilder.DropTable("BookRecord");
                SchemaBuilder.DropTable("BookCategoryRecord");
            }
            catch (Exception ex) {  
                System.Diagnostics.Trace.WriteLine(ex.Message);                 
            }
        }
        private readonly IEnumerable<AuthorBookRecord> _authorBook =
            new List<AuthorBookRecord> {
                new AuthorBookRecord {Description = "test", Firstname = "Stephen", Lastname="King"},
                new AuthorBookRecord {Description = "test", Firstname = "Dean", Lastname = "Koontz"},
                new AuthorBookRecord {Description = "test", Firstname = "Anne", Lastname = "Rice"}
            };
_"since AuthorBookRecord is a ContentPartRecord and part of a content part, why are you creating AuthorBookRecord instances directly, instead of using the content manager? I don't think content parts can live on their own without being part of a content item."
_

I agree with you, it's because I would like to do in two steps (because I don't know enough about the Orchard technical product, I need to do errors, I don't know the boundaries etc.)
First filled from Migration.
Second Step : create by the graphical interface => Ok I take a look, Create CustomContentType BookCustom, Add A field as Enumeration and a part Comments, good point.
But maybe it can be good to know how I can call a kind of services to filled the enumeration because this one needs to be available to construct the browse menu. Any advice?

[update]
I add the line ContentDefinitionManager.AlterPartDefinition("BookPart",
            builder => builder.Attachable());
Not solved, still the same issue.
Developer
Jun 1, 2013 at 12:28 PM
Ok, so if you want to work with DB entities first, don't have your record classes inherit from ContentPartRecord. Once you're ready to move on to working with content parts, turn your entity classes into part entities and start working with the content manager. I suspect that you're seeing the issue because ContentPartRecord references other objects which don't exist (e.,g. there's no content item).
Jun 1, 2013 at 4:34 PM
Edited Jun 1, 2013 at 5:03 PM
So i remove effectively the inherit part. But I don't modify the migrate class and before I realize my mistake, I enable the module.
Now I try to refresh the site /admin, /orchardlocal and try to launch the console.
Each time I obtain in the log
orchard> feature list /Summary:true

Error executing command "feature list"
--------------------------------------------------------------------------------


An association from the table CoinLecturePck_BookRecord refers to an unmapped cl
ass: CoinLecturePck.Models.BookCategoryRecord

Exception Details: NHibernate.MappingException: An association from the table Co
inLecturePck_BookRecord refers to an unmapped class: CoinLecturePck.Models.BookC
ategoryRecord

Stack Trace:
013-06-01 18:02:20,942 [39] Orchard.Data.SessionConfigurationCache - Error reading the cached NHibernate configuration: End of Stream encountered before parsing was completed.
2013-06-01 18:02:06,589 [39] Orchard.Environment.Extensions.ExtensionLoaderCoordinator - No loader found for extension "Orchard.Module.RelationSample"!
2013-06-01 18:02:06,598 [39] Orchard.Environment.Extensions.ExtensionLoaderCoordinator - No loader found for extension "Orchard.RelationSample"!
2013-06-01 18:02:06,607 [39] Orchard.Environment.Extensions.ExtensionLoaderCoordinator - No loader found for extension "orchardtrainingdemo"!
2013-06-01 18:02:20,942 [39] Orchard.Data.SessionConfigurationCache - Error reading the cached NHibernate configuration: End of Stream encountered before parsing was completed.
2013-06-01 18:02:21,208 [39] NHibernate.Cfg.Configuration - An association from the table CoinLecturePck_BookRecord refers to an unmapped class: CoinLecturePck.Models.BookCategoryRecord
NHibernate.MappingException: An association from the table CoinLecturePck_BookRecord refers to an unmapped class: CoinLecturePck.Models.BookCategoryRecord
2013-06-01 18:02:21,226 [39] Orchard.Environment.DefaultOrchardHost - A tenant could not be started: Default
NHibernate.MappingException: An association from the table CoinLecturePck_BookRecord refers to an unmapped class: CoinLecturePck.Models.BookCategoryRecord

--------------------------------------------------------------------------------
So I try to remove manually the 3 tables in the database, remove the line in the table [Orchard_Framework_DataMigrationRecord].
Try to iisreset.
Still the same issue, do you know where I delete this information and delete it?

I need to reset the configuration and delete the cache configuration.
So in debug I move in SessionConfigurationCache.cs

i think it's related to the code below, but i don't find how to solve.

In DefaultOrchardHost.cs
            // load all tenants, and activate their shell
            if (allSettings.Any()) {
                foreach (var settings in allSettings) {
                    try {
                        var context = CreateShellContext(settings);
                        ActivateShell(context);
                    }
                    catch(Exception e) {
                        Logger.Error(e, "A tenant could not be started: " + settings.Name);
                    }
                }
            }
Can't use anymore the console Orchard. too bad :(, maybe a command is available but I can't access.
I can just load Orchard and after each commands throws the exception.
http://docs.orchardproject.net/Documentation/Using-the-command-line-interface
Developer
Jun 1, 2013 at 7:17 PM
Perhaps simply wipe everything in App_Data and re-initialize your setup (unless you don't want to lose other data).
Jun 1, 2013 at 9:17 PM
Edited Jun 1, 2013 at 9:30 PM
Do you propose to reset the database?
It's not really possible, too easy ^^

I obtain an error after a little custom action and to be honest I would like to convince my developers team about the orchard product, so I would like to really have enough knowledge to go further. (because currently my team develop a cms from scratch and I think it can be possible to use Orchard but I can't say, Ok guys let's go on Orchard but ;))

So I continu to search.

[UPDATE]
Solved!
I play with many files in the folder App and now I can display the website and admin part.
Jun 3, 2013 at 7:01 AM
Hi,

I inactivate my custom to take another custom with boostraper.
I still obtain the issue
2013-06-03 07:52:19,492 [8] Orchard.Data.SessionConfigurationCache - Error reading the cached NHibernate configuration: End of Stream encountered before parsing was completed.
2013-06-03 07:52:19,729 [8] NHibernate.Cfg.Configuration - An association from the table CoinLecturePck_BookRecord refers to an unmapped class: CoinLecturePck.Models.BookCategoryRecord
NHibernate.MappingException: An association from the table CoinLecturePck_BookRecord refers to an unmapped class: CoinLecturePck.Models.BookCategoryRecord
2013-06-03 07:52:19,731 [8] Orchard.Environment.DefaultOrchardHost - A tenant could not be started: Default
NHibernate.MappingException: An association from the table CoinLecturePck_BookRecord refers to an unmapped class: CoinLecturePck.Models.BookCategoryRecord
In the folder App_Data\Dependencies, the two files dependencies.compiled.xml, dependencies.xml have one more time CoinLecture.
I remove these informations yesterday to avoid the technical issue.
It's not work today the same method.

So I delete all app folder.
Jun 3, 2013 at 9:06 PM
Edited Jun 3, 2013 at 9:08 PM
..... Ok I restart, I delete the first page created. and now I obtain

The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /OrchardLocal/

Good! I google "Default WebPage Orchard" no way... no answer..
Ok I search, you should deserve to use Orchard :( but I will ! => Set as homepage save my day :p