コード例 #1
0
        public void CommandTimeout()
        {
            string connectionString = String.Format(
                "metadata=res://*/TestModel.csdl|res://*/TestModel.ssdl|res://*/TestModel.msl;provider=MariaDB.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;
                }
            }
        }
コード例 #2
0
 /// <summary>
 /// Create a new Author object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 public static Author CreateAuthor(global::System.Int32 id, global::System.String name)
 {
     Author author = new Author();
     author.Id = id;
     author.Name = name;
     return author;
 }
コード例 #3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Authors EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToAuthors(Author author)
 {
     base.AddObject("Authors", author);
 }
コード例 #4
0
        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"]);
        }