public void write_then_read_from_stack_over_flow_types()
		{
			using (EmbeddableDocumentStore documentStore = NewDocumentStore())
			{
				IndexCreation.CreateIndexes(typeof (QuestionWithVoteTotalIndex).Assembly, documentStore);

				const string questionId = @"question\259";
				using (var 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 (var session = documentStore.OpenSession())
				{
					var questionInfo = session.Query<QuestionView, QuestionWithVoteTotalIndex>()
						.Customize(x => x.WaitForNonStaleResultsAsOfNow())
						.Where(x => x.QuestionId == questionId)
						.SingleOrDefault();
					Assert.NotNull(questionInfo);
					Assert.False(string.IsNullOrEmpty(questionInfo.User.DisplayName), "User.DisplayName was not loaded");
				}
			}
		}
예제 #2
0
		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);
				}
			}
		}
    	private string CreateEntities(EmbeddableDocumentStore documentStore)
        {
            const string questionId = @"question\259";
            const string answerId = @"answer\540";
            using (var 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
                                 };

                Answer answerDb = Map(answer);
                session.Store(answerDb);

                var vote1 = new AnswerVoteEntity { Id = "votes\\1", Answer = answer, QuestionId = questionId, Delta = 2 };
                AnswerVote vote1Db = Map(vote1);
                session.Store(vote1Db);

                var vote2 = new AnswerVoteEntity { Id = "votes\\2", Answer = answer, QuestionId = questionId, Delta = 3 };
                AnswerVote vote2Db = Map(vote2);
                session.Store(vote2Db);

                session.SaveChanges();
            }
            return answerId;
        }