none
Orchard Creating 1-n and n-n relations 问题 RRS feed

  • 问题

  • 我在学习 http://www.cnblogs.com/ibrady/archive/2012/03/22/2411920.html 里面的范例.
    在 Migrations 类中的 UpdateFrom1 方法里,添加一个 AddressPartRecord 记录:

    public int UpdateFrom1() {
                if (_stateRepository == null) throw new InvalidOperationException("Couldn't find state repository.");
                foreach (var state in _states) { _stateRepository.Create(state); }
    
                _addressRepository.Create(
                    new AddressPartRecord {
                        Address = "Address data",
                        City = "City data",
                        StateRecord = _states[5],
                        Zip = "Zip data"
                    }
                );
    }

    在启用与跟新该模块的时候抛出异常
    2013-06-25 04:11:11,078 [15] Orchard.Data.Migration.DataMigrationManager - An unexpected error orccured while applying migration on vwvjvwv.Orchard.Commerce.Measure from version 1
    System.Reflection.TargetInvocationException: 调用的目标发生了异常。 ---> NHibernate.Id.IdentifierGenerationException: attempted to assign id from null one-to-one property: ContentItemRecord

    _addressRepository.Create(
                    new AddressPartRecord {
                        Address = "Address data",
                        City = "City data",
                        StateRecord = _stateRepository.Get(2), // 修改
                        Zip = "Zip data"
                    }
    );

    我尝试跟换 StateRecord 的对象实例.可是问题依旧.
    不知道要如何插入 1-N 关系的数据呢?
    谢谢回复.

    2013年6月25日 1:28

全部回复