コード例 #1
0
ファイル: Program.cs プロジェクト: ajf2/orly-baga-fluent
        private static void InsertDestination()
        {
            var destination = new Destination
            {
                Country = "Indonesia",
                Description = "EcoTourism at its best in exquisite Bali",
                Name = "Bali"
            };
            using (var context = new BreakAwayContext())
            {
                context.Destinations.Add(destination);

                context.SaveChanges();
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: ajf2/orly-baga-fluent
 private static void InsertPerson()
 {
     var person = new Person
     {
         FirstName = "Rowan",
         LastName = "Miller",
         SocialSecurityNumber = 12345678,
         Photo = new PersonPhoto { Photo = new Byte[] { 0 } }
     };
     using (var context = new BreakAwayContext())
     {
         context.People.Add(person);
         context.SaveChanges();
     }
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: ajf2/orly-baga-fluent
        private static void InsertLodging()
        {
            var lodging = new Lodging()
            {
                Name = "Rainy Day Motel",
                Destination = new Destination
                {
                    Name = "Seattle, Washington",
                    Country = "USA"
                }
            };

            using (var context = new BreakAwayContext())
            {
                context.Lodgings.Add(lodging);
                context.SaveChanges();
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: ajf2/orly-baga-fluent
 private static void InsertResort()
 {
     var resort = new Resort
     {
         Name = "Top Notch Resort and Spa",
         MilesFromNearestAirport = 30,
         Activities = "Spa, Hiking, Skiing, Ballooning",
         Destination = new Destination
         {
             Name = "Stowe, Vermont",
             Country = "USA"
         }
     };
     using (var context = new BreakAwayContext())
     {
         context.Lodgings.Add(resort);
         context.SaveChanges();
     }
 }
コード例 #5
0
ファイル: Program.cs プロジェクト: ajf2/orly-baga-fluent
 private static void UpdateTrip()
 {
     using (var context = new BreakAwayContext())
     {
         var trip = context.Trips.FirstOrDefault();
         trip.CostUSD = 750;
         context.SaveChanges();
     }
 }
コード例 #6
0
ファイル: Program.cs プロジェクト: ajf2/orly-baga-fluent
 private static void UpdatePerson()
 {
     using (var context = new BreakAwayContext())
     {
         var person = context.People.Include("Photo").FirstOrDefault();
         person.FirstName = "Rowena";
         if (person.Photo == null)
         {
             person.Photo = new PersonPhoto { Photo = new Byte[] { 0 } };
         }
         context.SaveChanges();
     }
 }
コード例 #7
0
ファイル: Program.cs プロジェクト: ajf2/orly-baga-fluent
 private static void SpecifyDatabaseName()
 {
     using (var context = new BreakAwayContext("BreakAwayStringConstructor"))
     {
         context.Destinations.Add(new Destination { Name = "Tasmania" });
         context.SaveChanges();
     }
 }
コード例 #8
0
ファイル: Program.cs プロジェクト: ajf2/orly-baga-fluent
        //private static void DeleteDestinationInMemoryAndDbCascade()
        //{
        //    int destinationId;
        //    using (var context = new BreakAwayContext())
        //    {
        //        var destination = new Destination
        //        {
        //            Name = "Sample Destination",
        //            Lodgings = new List<Lodging> {
        //                new Lodging { Name = "Lodging One" },
        //                new Lodging { Name = "Lodging Two" }
        //            }
        //        };
        //        context.Destinations.Add(destination);
        //        context.SaveChanges();
        //        destinationId = destination.DestinationId;
        //    }
        //    using (var context = new BreakAwayContext())
        //    {
        //        var destination = context.Destinations
        //            .Single(d => d.DestinationId == destinationId);
        //        context.Destinations.Remove(destination);
        //        context.SaveChanges();
        //    }
        //    using (var context = new BreakAwayContext())
        //    {
        //        var lodgings = context.Lodgings
        //            .Where(l => l.DestinationId == destinationId).ToList();
        //        Console.WriteLine("Lodgings: {0}", lodgings.Count);
        //    }
        //}
        private static void RunTest()
        {
            using (var context = new BreakAwayContext())
            {
                context.Database.Initialize(force: true);

                context.Destinations.Add(new Destination { Name = "Fiji" });
                context.SaveChanges();
            }
            using (var context = new BreakAwayContext())
            {
                if (context.Destinations.Count() == 1)
                {
                    Console.WriteLine("Test Passed: 1 destination saved to database");
                }
                else
                {
                    Console.WriteLine("Test Failed: {0} destinations saved to database", context.Destinations.Count());
                }
            }
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: ajf2/orly-baga-fluent
        private static void ReuseDbConnection()
        {
            var cstr = @"Server=.\SQLEXPRESS;
                        Database=BreakAwayDbConnectionConstructor;
                        Trusted_Connection=true";

            using (var connection = new SqlConnection(cstr))
            {
                using (var context = new BreakAwayContext(connection))
                {
                    context.Destinations.Add(new Destination { Name = "Hawaii" });
                    context.SaveChanges();
                }

                using (var context = new BreakAwayContext(connection))
                {
                    foreach (var destination in context.Destinations)
                    {
                        Console.WriteLine(destination.Name);
                    }
                }
            }
        }
コード例 #10
0
ファイル: Program.cs プロジェクト: ajf2/orly-baga-fluent
 private static void InsertTrip()
 {
     var trip = new Trip
     {
         CostUSD = 800,
         StartDate = new System.DateTime(2011, 9, 1),
         EndDate = new System.DateTime(2011, 9, 14)
     };
     using (var context = new BreakAwayContext())
     {
         context.Trips.Add(trip);
         context.SaveChanges();
     }
 }