我第一次尝试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.
有人可以建议我的配置可能有什么问题吗?
答案 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; }
}