我有以下课程
Post.cs
public class Post: Neo4jEntity
{
public Post()
{
Label = "Post";
ID = Guid.NewGuid();
}
public Guid ID { get; set; }
public DateTime DateCreation { get; set; }
public string Content { get; set; }
}
Comment.cs
public class Comment:Neo4jEntity
{
public Comment()
{
Label = "Comment";
ID = new Guid();
}
public Guid ID { get; set; }
public string Content{ get; set; }
public DateTime CreationDate{ get; set; }
}
ApplicationUser.cs
public class ApplicationUser:IdentityUser
{
public ApplicationUser()
{
Label = "ApplicationUser";
}
public string FirstName{ get; set; }
public string SecondName{ get; set; }
public Sex Sex{ get; set; }//enum
}
我想从具有添加了ApplicationUser的评论的数据库所有帖子中获取。
var posts = _graphClient.Cypher
.Match("(user:ApplicationUser)-[:POST]-> (posts)-[:HAS]->comments<-[:ADD]-(users)")
.Return(()=>Return.As<Post>("posts","comments","users"))
.Limit(50)
.Results.ToList();
我想从此查询创建一个Model,然后将此Model传递给View,以生成如下内容:
foreach(var post in Model.Posts)
{
<div>@post.DateCreation</div>
<div>@post.Author.FirstName</div>
<div>@post.Content</div>
foreach(var comment in post.Comments)
{
<div>@comment.Author.Name</div>
<div>@comment.Content</div>
}
}
我不知道如何从cypher查询返回一个适合上述foreach的模型。我必须做一个有帖子,评论列表的ViewModel?如何添加评论的用户? 如何在C#中查询?