Esempio n. 1
0
        private Answer Map(AnswerEntity entity)
        {
            var answer = new Answer();

            answer.Id         = entity.Id;
            answer.UserId     = entity.UserId;
            answer.QuestionId = entity.Question.Id;
            answer.Content    = entity.Content;

            return(answer);
        }
Esempio n. 2
0
        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);
        }
        private Answer Map(AnswerEntity entity)
        {
            var answer = new Answer();
            answer.Id = entity.Id;
            answer.UserId = entity.UserId;
            answer.QuestionId = entity.Question.Id;
            answer.Content = entity.Content;

            return answer;
        }
    	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;
        }