私はこの2つのクラスを持っています:
public class BlogPost
{
public string Id { get; set; }
public string Title { get; set; }
public string Category { get; set; }
public string Content { get; set; }
public DateTime PublishedAt { get; set; }
public string[] Tags { get; set; }
public BlogComment[] Comments { get; set; }
}
public class BlogComment
{
public string Id { get; set; }
public string Title { get; set; }
public string Content { get; set; }
}
次のようなドキュメントに追加します。
// Creating a new instance of the BlogPost class
BlogPost post = new BlogPost()
{
Title = "Hello RavenDB",
Category = "RavenDB",
Content = "This is a blog about RavenDB",
Comments = new BlogComment[]
{
new BlogComment() {Title = "Unrealistic", Content = "This example is unrealistic"},
new BlogComment() {Title = "Nice", Content = "This example is nice"}
}
};
コメントにBlogPostクラスのような Identity キーを付ける方法はありますか?
別の質問: 投稿を使用せずにコメント オブジェクトを取得する方法はありますか。このようなもの :
using( var session = doc.OpenSession() )
{
return session.Load<BlogComment>( ID );
}
また
using( var session = doc.OpenSession() )
{
return ( from comment in session.Query<BlogComment>()
where comment.Title == title
select comment ).FirstOrDefault();
}