Castle Active Record - 嵌套数据列前缀

时间:2012-12-05 01:30:47

标签: nhibernate castle-activerecord

我有一些类似于下面所示的类。

[ActiveRecord]
public class Request : ActiveRecordBase
{
    [PrimaryKey]
    public int Id {get; set;}

    [Nested("SectionA")]
    public SectionA A {get; set;}

    [Nested("SectionB")]
    public SectionB B {get; set;}

}

public class SectionA
{
    [Property]
    public string Description {get; set;}

    [Property]
    public string Remark {get; set;}

    [HasMany(typeof(Attachment), 
             Table="Attachments", ColumnKey="RequestId",
             Where="Section = 'SectionA'")]
    public IList Attachments {get; set;}
}

public class SectionB
{
    [Property]
    public string Description {get; set;}

    [HasMany(typeof(Attachment), 
             Table="Attachments", ColumnKey="RequestId",
             Where="Section = 'SectionB'")]
    public IList Attachments {get; set;}

}

[ActiveRecord]
public class Attachment
{
    [PrimaryKey]
    public int Id {get; set;}

    [BelongsTo("RequestId")]
    public Request Owner {get; set;}

    [Property]
    public string Section {get; set;}

    [Property]
    public string FilePath {get; set;}
}

一切正常,但Attachment Class的列也会有前缀。并且它发生在相当随机的情况下,因为在某些时候它确实有前缀,有时它没有。

有没有办法阻止附件具有前缀,或者是否有更好的方法来构建防止此问题的类。

1 个答案:

答案 0 :(得分:0)

似乎是防止Attachment类上的嵌套前缀是连接Request&直接附件。仍然需要观察几次迭代。

[ActiveRecord]
public class Request : ActiveRecordBase
{
    [PrimaryKey]
    public int Id {get; set;}

    [HasMany(typeof(Attachment)]
    public IList Attachments {get; set;}

    [Nested("SectionA")]
    public SectionA A {get; set;}

    [Nested("SectionB")]
    public SectionB B {get; set;}

}