Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
        public static string CreateEntities(IDocumentStore documentStore, int index)
        {
            string questionId = @"question/259" + index;
            string answerId   = @"answer/540" + index;

            using (IDocumentSession session = documentStore.OpenSession())
            {
                var user = new User {
                    Id = @"user/222" + index, DisplayName = "John Doe" + index
                };
                session.Store(user);

                var question = new Question
                {
                    Id      = questionId,
                    Title   = "How to do this in RavenDb?" + index,
                    Content = "I'm trying to find how to model documents for better DDD support." + index,
                    UserId  = @"user/222" + index
                };
                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" + index, 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" + index, Answer = answer, QuestionId = questionId, Delta = 3
                };
                session.Store(new AnswerVote
                {
                    QuestionId = vote2.QuestionId,
                    AnswerId   = vote2.Answer.Id,
                    Delta      = vote2.Delta
                });

                session.SaveChanges();
            }
            return(answerId);
        }