public static string CreateEntities(IDocumentStore documentStore) { const string questionId = @"question/259"; const string answerId = @"answer/540"; using (IDocumentSession session = documentStore.OpenSession()) { var user = new User { Id = @"user/222", DisplayName = "John Doe" }; session.Store(user); var question = new Question { Id = questionId, Title = "How to do this in RavenDb?", Content = "I'm trying to find how to model documents for better DDD support.", UserId = @"user/222" }; session.Store(question); var answer = new AnswerEntity { Id = answerId, Question = question, Content = "This is doable", UserId = user.Id }; session.Store(new Answer { Id = answer.Id, UserId = answer.UserId, QuestionId = answer.Question.Id, Content = answer.Content }); var vote1 = new AnswerVoteEntity { Id = "votes/1", Answer = answer, QuestionId = questionId, Delta = 2 }; session.Store(new AnswerVote { QuestionId = vote1.QuestionId, AnswerId = vote1.Answer.Id, Delta = vote1.Delta }); var vote2 = new AnswerVoteEntity { Id = "votes/2", Answer = answer, QuestionId = questionId, Delta = 3 }; session.Store(new AnswerVote { QuestionId = vote2.QuestionId, AnswerId = vote2.Answer.Id, Delta = vote2.Delta }); session.SaveChanges(); } return answerId; }
public void write_then_read_from_stack_over_flow_types() { using (EmbeddableDocumentStore documentStore = NewDocumentStore()) { new QuestionWithVoteTotalIndex().Execute(documentStore); new QuestionWithVoteTotalTransformer().Execute(documentStore); const string questionId = @"question/259"; using (IDocumentSession session = documentStore.OpenSession()) { var user = new User { Id = @"user/222", DisplayName = "John Doe" }; session.Store(user); var question = new Question { Id = questionId, Title = "How to do this in RavenDb?", Content = "I'm trying to find how to model documents for better DDD support.", UserId = @"user/222" }; session.Store(question); var vote1 = new QuestionVote { QuestionId = questionId, Delta = 2 }; session.Store(vote1); var vote2 = new QuestionVote { QuestionId = questionId, Delta = 3 }; session.Store(vote2); session.SaveChanges(); } using (IDocumentSession session = documentStore.OpenSession()) { QuestionView questionInfo = session.Query<QuestionView, QuestionWithVoteTotalIndex>() .Customize(x => x.WaitForNonStaleResultsAsOfNow()) .Where(x => x.QuestionId == questionId) .TransformWith<QuestionWithVoteTotalTransformer, QuestionView>() .SingleOrDefault(); Assert.NotNull(questionInfo); Assert.False(string.IsNullOrEmpty(questionInfo.User.DisplayName), "User.DisplayName was not loaded"); } } }
public void CanQueryById() { using (var store = NewDocumentStore()) { const string questionId = @"question/259"; using (var session = store.OpenSession()) { var user = new User(); user.Id = @"user/222"; user.Name = "John Doe"; session.Store(user); var question = new Question(); question.Id = questionId; question.Title = "How to to this in RavenDb?"; question.Content = "I'm trying to find how to model documents for better DDD support."; question.UserId = @"user/222"; session.Store(question); session.SaveChanges(); var questionInfo1 = session.Load<Question>(questionId); Assert.NotNull(questionInfo1); Question questionInfo2 = session.Query<Question>() .Customize(y => y.WaitForNonStaleResults()) .Where(x => x.Id == questionId) .SingleOrDefault(); Assert.NotNull(questionInfo2); Question questionInfo3 = session.Query<Question>() .Customize(y => y.WaitForNonStaleResults()) .Where(x => x.UserId == @"user/222") .SingleOrDefault(); Assert.NotNull(questionInfo3); } } }
public static string CreateEntities(IDocumentStore documentStore) { const string questionId = @"question/259"; const string answerId = @"answer/540"; using (IDocumentSession session = documentStore.OpenSession()) { var user = new User { Id = @"user/222", DisplayName = "John Doe" }; session.Store(user); var question = new Question { Id = questionId, Title = "How to do this in RavenDb?", Content = "I'm trying to find how to model documents for better DDD support.", UserId = @"user/222" }; session.Store(question); var answer = new AnswerEntity { Id = answerId, Question = question, Content = "This is doable", UserId = user.Id }; session.Store(new Answer { Id = answer.Id, UserId = answer.UserId, QuestionId = answer.Question.Id, Content = answer.Content }); var vote1 = new AnswerVoteEntity { Id = "votes/1", Answer = answer, QuestionId = questionId, Delta = 2 }; session.Store(new AnswerVote { QuestionId = vote1.QuestionId, AnswerId = vote1.Answer.Id, Delta = vote1.Delta }); var vote2 = new AnswerVoteEntity { Id = "votes/2", Answer = answer, QuestionId = questionId, Delta = 3 }; session.Store(new AnswerVote { QuestionId = vote2.QuestionId, AnswerId = vote2.Answer.Id, Delta = vote2.Delta }); session.SaveChanges(); } return(answerId); }