コード例 #1
0
        public static IList <ReviewComplexData> FindReviewsByPeriod(DateTime startDate, DateTime endDate)
        {
            BookstoreEntities context = new BookstoreEntities();

            var reviewsQuery =
                from r in context.Reviews
                where r.CreationDate >= startDate && r.CreationDate <= endDate
                select new ReviewComplexData()
            {
                Date    = r.CreationDate,
                Content = r.Text,
                Book    = r.Book,
                Authors = r.Book.Authors
            };

            reviewsQuery = reviewsQuery.OrderBy(r => r.Date).ThenBy(r => r.Content);

            return(reviewsQuery.ToList <ReviewComplexData>());
        }
コード例 #2
0
        private static Author CreateOrLoadAuthor(
            BookstoreEntities context, string authorName)
        {
            Author existAuthor =
                (from a in context.Authors
                 where a.Name == authorName
                 select a).FirstOrDefault();

            if (existAuthor != null)
            {
                return(existAuthor);
            }

            Author newAuthor = new Author();

            newAuthor.Name = authorName;
            context.Authors.Add(newAuthor);
            context.SaveChanges();

            return(newAuthor);
        }