ActiveRecord异常:找不到配置

时间:2014-03-21 18:29:13

标签: c# nhibernate activerecord configuration

我第一次尝试Castle.ActiveRecord。我在我的模型中定义了以下类:

[ActiveRecord("ClientObjects")]
public class ClientObject : ActiveRecordBase<ClientObject>
{
    [PrimaryKey]
    public virtual Guid Id { get; set; }

    [BelongsTo("ClientId", NotNull = true, UniqueKey = "uxClientObjects.Client.Name")]
    public virtual Client Client { get; set; }

    [Property(NotNull = true, Length = 250)]
    public virtual string Type { get; set; }

    [Property(NotNull = true, Length = 70, UniqueKey = "uxClientObjects.Client.Name")]
    public virtual string Name { get; set; }

    [HasMany(typeof(ClientGroupAccess), ColumnKey = "ClientObjectId", Table = "ClientGroupAccess")]
    public virtual IList<ClientGroupAccess> ObjectAccess { get; set; }
}

...当我尝试生成sql时,我得到一个例外:

ActiveRecordException: Could not find configuration for (my namespace).Entities.ClientObject or its root type Castle.ActiveRecord.ActiveRecordBase this is usually an indication that the configuration has not been setup correctly.

有人可以建议我的配置可能有什么问题吗?

1 个答案:

答案 0 :(得分:0)

看起来需要设置Inverse属性:

[ActiveRecord("ClientObjects")]
public class ClientObject : ActiveRecordBase<ClientObject>
{
    [PrimaryKey]
    public virtual Guid Id { get; set; }

    [BelongsTo("ClientId", NotNull = true, UniqueKey = "uxClientObjects.Client.Name")]
    public virtual Client Client { get; set; }

    [Property(NotNull = true, Length = 250)]
    public virtual string Type { get; set; }

    [Property(NotNull = true, Length = 70, UniqueKey = "uxClientObjects.Client.Name")]
    public virtual string Name { get; set; }

    [HasMany(typeof(ClientGroupAccess), Inverse = true)]
    public virtual IList<ClientGroupAccess> ObjectAccess { get; set; }
}