1

私はこの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();
}
4

1 に答える 1

0

BlogPostに整数プロパティを設定し、それをインクリメントして、新しいコメントを追加するたびにその値を設定できます。これにより、投稿の範囲内でIDスタイルIDが得られます。

于 2013-03-03T04:07:40.720 に答える