当前位置: 首页>>代码示例>>C#>>正文


C# testEntities.SaveChanges方法代码示例

本文整理汇总了C#中MySql.Data.Entity.Tests.testEntities.SaveChanges方法的典型用法代码示例。如果您正苦于以下问题:C# testEntities.SaveChanges方法的具体用法?C# testEntities.SaveChanges怎么用?C# testEntities.SaveChanges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MySql.Data.Entity.Tests.testEntities的用法示例。


在下文中一共展示了testEntities.SaveChanges方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UpdateSimple

    public void UpdateSimple()
    {      
      using (testEntities context = new testEntities())
      {        
        MySqlTrace.Listeners.Clear();
        MySqlTrace.Switch.Level = SourceLevels.All;
        GenericListener listener = new GenericListener();
        MySqlTrace.Listeners.Add(listener);
        Product pc = null;
        try
        {
          pc = new Product();
          pc.Name= "Acme";
          context.AddToProducts(pc);
          context.SaveChanges();
          pc.Name = "Acme 2";
          context.SaveChanges();
        }
        finally
        {
#if CLR4
          context.Products.DeleteObject(pc);
#endif
        }
        // Check sql        
        Regex rx = new Regex(@"Query Opened: (?<item>UPDATE .*)", RegexOptions.Compiled | RegexOptions.Singleline);
        foreach( string s in listener.Strings )
        {
          Match m = rx.Match(s);
          if (m.Success)
          {
            CheckSql(m.Groups["item"].Value, SQLSyntax.UpdateWithSelect);
            Assert.Pass();
          }
        }
        Assert.Fail();
      }
    }
开发者ID:brunolauze,项目名称:mysql-connector-net-6,代码行数:38,代码来源:UpdateTests.cs

示例2: CanInsertRowWithDefaultTimeStamp

        public void CanInsertRowWithDefaultTimeStamp()
        {
            using (testEntities context = new testEntities())
              {
            // The default timestamp is in the CreatedDate column.
            Product product = new Product();
            product.Name = "Coca Cola";

            context.AddToProducts(product);
            context.SaveChanges();

            Assert.AreEqual(DateTime.Today.Day, product.CreatedDate.Day);
              }
        }
开发者ID:schivei,项目名称:mysql-connector-net,代码行数:14,代码来源:InsertTests.cs

示例3: UpdateAllRows

    public void UpdateAllRows()
    {
      MySqlCommand cmd = new MySqlCommand("SELECT COUNT(*) FROM toys", conn);
      object count = cmd.ExecuteScalar();

      using (testEntities context = new testEntities())
      {
        foreach (Toy t in context.Toys)
          t.Name = "Top";
        context.SaveChanges();
      }

      cmd.CommandText = "SELECT COUNT(*) FROM Toys WHERE name='Top'";
      object newCount = cmd.ExecuteScalar();
      Assert.AreEqual(count, newCount);
    }
开发者ID:brunolauze,项目名称:mysql-connector-net-6,代码行数:16,代码来源:UpdateTests.cs

示例4: SimpleDeleteAllRows

        public void SimpleDeleteAllRows()
        {
            using (testEntities context = new testEntities())
            {
                foreach (Toy t in context.Toys)
                    context.DeleteObject(t);
                context.SaveChanges();

                EntityConnection ec = context.Connection as EntityConnection;
                MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM toys",
                    (MySqlConnection)ec.StoreConnection);
                DataTable dt = new DataTable();
                da.Fill(dt);
                Assert.AreEqual(0, dt.Rows.Count);
            }
        }
开发者ID:elevate,项目名称:mysqlconnector-.net,代码行数:16,代码来源:DeleteTests.cs

示例5: SimpleDeleteRowByParameter

        public void SimpleDeleteRowByParameter()
        {
            using (testEntities context = new testEntities())
            {
                MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM toys WHERE minage=3", conn);
                DataTable dt = new DataTable();
                da.Fill(dt);
                Assert.IsTrue(dt.Rows.Count > 0);

                ObjectQuery<Toy> toys = context.Toys.Where("it.MinAge = @age", new ObjectParameter("age", 3));
                foreach (Toy t in toys)
                    context.DeleteObject(t);
                context.SaveChanges();

                dt.Clear();
                da.Fill(dt);
                Assert.AreEqual(0, dt.Rows.Count);
            }
        }
开发者ID:elevate,项目名称:mysqlconnector-.net,代码行数:19,代码来源:DeleteTests.cs

示例6: TimeType

        public void TimeType()
        {
            using (testEntities context = new testEntities())
            {
                TimeSpan birth = new TimeSpan(11,3,2);

                Child c = new Child();
                c.Id = 20;
                c.EmployeeID = 1;
                c.FirstName = "first";
                c.LastName = "last";
                c.BirthTime = birth;
                context.AddToChildren(c);
                context.SaveChanges();

                MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM EmployeeChildren WHERE id=20", conn);
                DataTable dt = new DataTable();
                da.Fill(dt);
                Assert.AreEqual(birth, dt.Rows[0]["birthtime"]);
            }
        }
开发者ID:LittlePeng,项目名称:ncuhome,代码行数:21,代码来源:DataTypeTests.cs

示例7: InsertSingleRow

        public void InsertSingleRow()
        {
            MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM companies", conn);
              DataTable dt = new DataTable();
              da.Fill(dt);
              DataRow lastRow = dt.Rows[dt.Rows.Count - 1];
              int lastId = (int)lastRow["id"];
              DateTime dateBegan = DateTime.Now;

              using (testEntities context = new testEntities())
              {
            Company c = new Company();
            c.Id = 23;
            c.Name = "Yoyo";
            c.NumEmployees = 486;
            c.DateBegan = dateBegan;
            c.Address.Address = "212 My Street.";
            c.Address.City = "Helena";
            c.Address.State = "MT";
            c.Address.ZipCode = "44558";

            context.AddToCompanies(c);
            int result = context.SaveChanges();

            DataTable afterInsert = new DataTable();
            da.Fill(afterInsert);
            lastRow = afterInsert.Rows[afterInsert.Rows.Count - 1];

            Assert.AreEqual(dt.Rows.Count + 1, afterInsert.Rows.Count);
            Assert.AreEqual(lastId + 1, lastRow["id"]);
            Assert.AreEqual("Yoyo", lastRow["name"]);
            Assert.AreEqual(486, lastRow["numemployees"]);
            DateTime insertedDT = (DateTime)lastRow["dateBegan"];
            Assert.AreEqual(dateBegan.Date, insertedDT.Date);
            Assert.AreEqual("212 My Street.", lastRow["address"]);
            Assert.AreEqual("Helena", lastRow["city"]);
            Assert.AreEqual("MT", lastRow["state"]);
            Assert.AreEqual("44558", lastRow["zipcode"]);
              }
        }
开发者ID:schivei,项目名称:mysql-connector-net,代码行数:40,代码来源:InsertTests.cs

示例8: Update

    public void Update()
    {
      MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Authors", conn);
      DataTable dt = new DataTable();
      da.Fill(dt);
      int count = dt.Rows.Count;

      using (testEntities context = new testEntities())
      {
        var q = from a in context.Authors
                where a.Name == "Don Box"
                select a;
        foreach (Author a in q)
          a.Name = "Dummy";
        context.SaveChanges();
      }

      da.SelectCommand.CommandText = "SELECT * FROM Authors WHERE name='Dummy'";
      dt.Clear();
      da.Fill(dt);
      Assert.AreEqual(1, dt.Rows.Count);
    }
开发者ID:brunolauze,项目名称:mysql-connector-net-6,代码行数:22,代码来源:ProceduresAndFunctions.cs

示例9: Insert

    public void Insert()
    {
      MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Authors", conn);
      DataTable dt = new DataTable();
      da.Fill(dt);
      int count = dt.Rows.Count;

      using (testEntities context = new testEntities())
      {
        Author a = new Author();
        a.Id = 23;
        a.Name = "Test name";
        a.Age = 44;
        context.AddToAuthors(a);
        context.SaveChanges();
      }

      dt.Clear();
      da.Fill(dt);
      Assert.AreEqual(count + 1, dt.Rows.Count);
      Assert.AreEqual(23, dt.Rows[count]["id"]);
    }
开发者ID:brunolauze,项目名称:mysql-connector-net-6,代码行数:22,代码来源:ProceduresAndFunctions.cs

示例10: CommandTimeout

        public void CommandTimeout()
        {
            string connectionString = String.Format(
              "metadata=res://*/TestModel.csdl|res://*/TestModel.ssdl|res://*/TestModel.msl;provider=MySql.Data.MySqlClient; provider connection string=\"{0};default command timeout=5\"", GetConnectionString(true));
              EntityConnection connection = new EntityConnection(connectionString);

              using (testEntities context = new testEntities(connection))
              {
            Author a = new Author();
            a.Id = 66;  // special value to indicate the routine should take 30 seconds
            a.Name = "Test name";
            a.Age = 44;
            context.AddToAuthors(a);
            try
            {
              context.SaveChanges();
              Assert.Fail("This should have timed out");
            }
            catch (Exception ex)
            {
              string s = ex.Message;
            }
              }
        }
开发者ID:schivei,项目名称:mysql-connector-net,代码行数:24,代码来源:ProceduresAndFunctions.cs

示例11: Delete

    public void Delete()
    {
      using (testEntities context = new testEntities())
      {
        foreach (Book b in context.Books)
          context.DeleteObject(b);
        context.SaveChanges();
      }

      MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Books", conn);
      DataTable dt = new DataTable();
      da.Fill(dt);
      Assert.AreEqual(0, dt.Rows.Count);
    }
开发者ID:brunolauze,项目名称:mysql-connector-net-6,代码行数:14,代码来源:ProceduresAndFunctions.cs

示例12: DefaultCommandTimeOutNotWorking

        public void DefaultCommandTimeOutNotWorking()
        {
            string connectionString = String.Format(
              "metadata=res://*/TestModel.csdl|res://*/TestModel.ssdl|res://*/TestModel.msl;provider=MySql.Data.MySqlClient; provider connection string=\"{0};Use Default Command Timeout For EF=true; Default Command Timeout=5;\"", GetConnectionString(true));
              //EntityConnection connection = new EntityConnection(connectionString);

              using (testEntities context = new testEntities(connectionString))
              {
            Author a = new Author();
            a.Id = 66;  // special value to indicate the routine should take 30 seconds
            a.Name = "Test name";
            a.Age = 44;
            context.AddToAuthors(a);
            try
            {
              context.SaveChanges();
              Assert.Fail("This should have timed out");
            }
            catch (Exception ex)
            {
              Exception innerException = ex.InnerException;
              Assert.AreEqual("Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.", innerException.Message);
            }
              }
        }
开发者ID:schivei,项目名称:mysql-connector-net,代码行数:25,代码来源:ProceduresAndFunctions.cs

示例13: DoubleValuesNonEnglish

        public void DoubleValuesNonEnglish()
        {
            CultureInfo curCulture = Thread.CurrentThread.CurrentCulture;
            CultureInfo curUICulture = Thread.CurrentThread.CurrentUICulture;
            CultureInfo newCulture = new CultureInfo("da-DK");
            Thread.CurrentThread.CurrentCulture = newCulture;
            Thread.CurrentThread.CurrentUICulture = newCulture;

            try
            {
                using (testEntities context = new testEntities())
                {
                    Child c = new Child();
                    c.Id = 20;
                    c.EmployeeID = 1;
                    c.FirstName = "Bam bam";
                    c.LastName = "Rubble";
                    c.BirthWeight = 8.65;
                    context.AddToChildren(c);
                    context.SaveChanges();
                }
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture = curCulture;
                Thread.CurrentThread.CurrentUICulture = curUICulture;
            }
        }
开发者ID:LittlePeng,项目名称:ncuhome,代码行数:28,代码来源:DataTypeTests.cs

示例14: TimestampColumn

        public void TimestampColumn()
        {
            DateTime now = DateTime.Now;

            using (testEntities context = new testEntities())
            {
                Child c = context.Children.First();
                DateTime dt = c.Modified.DateTime;
                c.Modified = now;
                context.SaveChanges();

                c = context.Children.First();
                dt = c.Modified.DateTime;
                Assert.AreEqual(now, dt);
            }
        }
开发者ID:LittlePeng,项目名称:ncuhome,代码行数:16,代码来源:DataTypeTests.cs


注:本文中的MySql.Data.Entity.Tests.testEntities.SaveChanges方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。