向ravenDB中的子类添加标识键
我有两门课:向ravenDB中的子类添加标识键,ravendb,Ravendb,我有两门课: 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[]
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"}
}
};
using( var session = doc.OpenSession() )
{
return session.Load<BlogComment>( ID );
}
有没有一种方法可以让我的评论像我的BlogPost类一样具有标识键
还有一个问题:
有没有一种方法可以在不使用post的情况下获取注释对象。大概是这样的:
// 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"}
}
};
using( var session = doc.OpenSession() )
{
return session.Load<BlogComment>( ID );
}
使用(var session=doc.OpenSession())
{
返回会话加载(ID);
}
或
使用(var session=doc.OpenSession())
{
返回(来自session.Query()中的注释)
其中comment.Title==Title
选择comment).FirstOrDefault();
}
只要在BlogPost上有一个integer属性,增加该属性,并在添加新注释时设置该值即可。这将为您提供帖子范围内的标识样式ID