コード例 #1
0
 private static void DoCustomerActions()
 {
     using (var ctx = new AdventureWorksLT2012Entities())
     {
         Commit(ctx);
     }
 }
コード例 #2
0
 static void Main(string[] args)
 {
     using (var ctx = new AdventureWorksLT2012Entities())
     {
         DoCustomerActions();
     }
 }
コード例 #3
0
        private static void CreateCustomer(AdventureWorksLT2012Entities ctx)
        {
            var customer = new Customer()
            {
                FirstName    = "John",
                LastName     = "Smith",
                PasswordHash = "xyz",
                PasswordSalt = "abc",
                rowguid      = Guid.NewGuid()
            };

            ctx.Customers.Add(customer);
        }
コード例 #4
0
 private static void Commit(AdventureWorksLT2012Entities ctx)
 {
     try
     {
         ctx.SaveChanges();
     }
     catch (DbEntityValidationException e)
     {
         foreach (var eve in e.EntityValidationErrors)
         {
             Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                               eve.Entry.Entity.GetType().Name, eve.Entry.State);
             foreach (var ve in eve.ValidationErrors)
             {
                 Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                   ve.PropertyName, ve.ErrorMessage);
             }
         }
         throw;
     }
 }