【问题标题】:Orchard CMS record mapping from external Assembly来自外部程序集的 Orchard CMS 记录映射
【发布时间】:2015-01-24 17:48:03
【问题描述】:

我有一个使用外部库的 Orchard CMS 模块。我需要使用该库中的一些类作为 Orchard 记录的一部分。 例如,外部程序集包含类

public class Operation {
    public virtual long Id { get; set; }
    public virtual string OperationType { get; set; } 
}

我必须将其存储在数据库中,以便与 Orchard IRepository 一起使用,并将其用作其他 Orchard CMS 记录的一部分,例如

public class HistoryRecord {    
    public virtual long Id { get; set; }
    public virtual DateTime Updated { get; set; }
    public virtual Operation Operation { get; set; }
}

【问题讨论】:

  • 我认为你做不到。您应该尝试寻找另一种与外部系统交互的方式。

标签: orchardcms nhibernate-mapping orchardcms-1.8


【解决方案1】:

我能够获得基于Fluet Configuration 的部分解决方案。然而,它只有在类符合 Orchard 的命名约定时才有效。 这里是:

public class SessionConfiguration : ISessionConfigurationEvents {
    public void Created(FluentConfiguration cfg, AutoPersistenceModel defaultModel) {
        var ts = new TypeSource(new[] { typeof(OperationRecord) });
        cfg.Mappings(m => m.AutoMappings.Add(AutoMap.Source(ts)
                .Override<OperationRecord>(mapping => mapping.Table("Custom_Module_OperationRecord"))
            ));
    }

    public void Prepared(FluentConfiguration cfg) { }
    public void Building(Configuration cfg) { }
    public void Finished(Configuration cfg) { }
    public void ComputingHash(Hash hash) { }
}


public class TypeSource : ITypeSource {
    private readonly IEnumerable<Type> _types;
    public TypeSource(IEnumerable<Type> types) {
        _types = types;
    }
    public IEnumerable<Type> GetTypes() {
        return _types;
    }
    public void LogSource(IDiagnosticLogger logger) {
        throw new NotImplementedException();
    }
    public string GetIdentifier() {
        throw new NotImplementedException();
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-02
    • 1970-01-01
    • 2017-10-05
    • 1970-01-01
    • 1970-01-01
    • 2011-01-05
    相关资源
    最近更新 更多