예제 #1
0
        static void RunExample()
        {
            using (var context = new EFRecipesEntities())
            {
                var mr1 = new MovieRental {
                    Title = "A Day in the Life", RentalDate = DateTime.Parse("2/19/2010"), ReturnedDate = DateTime.Parse("3/4/2010"), LateFees = 3M
                };
                var mr2 = new MovieRental {
                    Title = "The Shortest Yard", RentalDate = DateTime.Parse("3/15/2010"), ReturnedDate = DateTime.Parse("3/20/2010"), LateFees = 0M
                };
                var mr3 = new MovieRental {
                    Title = "Jim's Story", RentalDate = DateTime.Parse("3/2/2010"), ReturnedDate = DateTime.Parse("3/19/2010"), LateFees = 3M
                };
                context.MovieRentals.AddObject(mr1);
                context.MovieRentals.AddObject(mr2);
                context.MovieRentals.AddObject(mr3);
                context.SaveChanges();
            }

            using (var context = new EFRecipesEntities())
            {
                Console.WriteLine("Movie rentals late returns");
                Console.WriteLine("==========================");
                var late = from r in context.MovieRentals
                           where EntityFunctions.DiffDays(r.RentalDate, r.ReturnedDate) > 10
                           select r;
                foreach (var rental in late)
                {
                    Console.WriteLine("{0} was {1} days late, fee: {2}", rental.Title, (rental.ReturnedDate - rental.RentalDate).Days - 10, rental.LateFees.ToString("C"));
                }
            }

            Console.WriteLine("Press <enter> to continue...");
            Console.ReadLine();
        }
        /// <summary>
        /// Create a new MovieRental object.
        /// </summary>
        /// <param name="rentalId">Initial value of the RentalId property.</param>
        /// <param name="title">Initial value of the Title property.</param>
        /// <param name="rentalDate">Initial value of the RentalDate property.</param>
        /// <param name="returnedDate">Initial value of the ReturnedDate property.</param>
        /// <param name="lateFees">Initial value of the LateFees property.</param>
        public static MovieRental CreateMovieRental(global::System.Int32 rentalId, global::System.String title, global::System.DateTime rentalDate, global::System.DateTime returnedDate, global::System.Decimal lateFees)
        {
            MovieRental movieRental = new MovieRental();

            movieRental.RentalId = rentalId;

            movieRental.Title = title;

            movieRental.RentalDate = rentalDate;

            movieRental.ReturnedDate = returnedDate;

            movieRental.LateFees = lateFees;

            return(movieRental);
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the MovieRentals EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToMovieRentals(MovieRental movieRental)
 {
     base.AddObject("MovieRentals", movieRental);
 }