0
我正在使用Castle ActiveRecord重組我們的數據庫訪問權限。我已經通過博客/後期示例來了解事情的完成情況,但是我有一個關於HasMany屬性的基本問題。請看下面的例子:Castle ActiveRecord HasMany屬性
班級博客:
[ActiveRecord]
public class Blog : ActiveRecordBase
{
private int id;
private IList posts = new ArrayList();
public Blog()
{
}
[PrimaryKey]
public int Id
{
get { return id; }
set { id = value; }
}
[HasMany(typeof(Post), Table="Posts", ColumnKey="blogid",
Inverse=true, Cascade=ManyRelationCascadeEnum.AllDeleteOrphan)]
public IList Posts
{
get { return posts; }
set { posts = value; }
}
}
類崗位:
[ActiveRecord]
public class Post : ActiveRecordBase
{
private int id;
private String contents;
private Blog blog;
public Post()
{
}
[PrimaryKey]
public int Id
{
get { return id; }
set { id = value; }
}
[Property(ColumnType="StringClob")]
public String Contents
{
get { return contents; }
set { contents = value; }
}
[BelongsTo("blogid")]
public Blog Blog
{
get { return blog; }
set { blog = value; }
}
}
現在當我創建一個博客,並添加一些職位,以這個博客,爲什麼是Blog.Posts集合不會自動更新?這是代碼:
using (new SessionScope())
{
Blog b = new Blog();
b.Save();
Post p = new Post();
p.Blog = b;
p.Save();
//Here, b.Posts is empty, but shouldn't it contain a reference to p?
}
可以做些什麼來防止這種行爲?我必須手動將帖子添加到收藏夾嗎?這裏有什麼最佳實踐?
TIA