本文整理汇总了C#中MySql.Data.Entity.Tests.testEntities类的典型用法代码示例。如果您正苦于以下问题:C# testEntities类的具体用法?C# testEntities怎么用?C# testEntities使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
testEntities类属于MySql.Data.Entity.Tests命名空间,在下文中一共展示了testEntities类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateDatabaseScript
public void CreateDatabaseScript()
{
using (testEntities ctx = new testEntities())
{
string s = ctx.CreateDatabaseScript();
}
}
示例2: AverageWithGrouping
public void AverageWithGrouping()
{
MySqlDataAdapter da = new MySqlDataAdapter(
"SELECT AVG(Freight) FROM Orders GROUP BY ShopId", conn);
DataTable dt = new DataTable();
da.Fill(dt);
using (testEntities context = new testEntities())
{
string eSql = "SELECT AVG(o.Freight) FROM Orders AS o GROUP BY o.Shop.Id";
ObjectQuery<DbDataRecord> q = context.CreateQuery<DbDataRecord>(eSql);
string sql = q.ToTraceString();
CheckSql(sql, SQLSyntax.AverageWithGrouping);
foreach (object x in q)
{
string s = x.GetType().ToString();
}
int i = 0;
foreach (var freight in q)
{
// Assert.AreEqual(Convert.ToInt32(dt.Rows[i++][0]), Convert.ToInt32(freight));
}
}
}
示例3: 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;
c.Modified = DateTime.Now;
context.AddToChildren(c);
context.SaveChanges();
}
}
finally
{
Thread.CurrentThread.CurrentCulture = curCulture;
Thread.CurrentThread.CurrentUICulture = curUICulture;
}
}
示例4: SimpleJoinWithPredicate
public void SimpleJoinWithPredicate()
{
MySqlDataAdapter da = new MySqlDataAdapter(
@"SELECT b.id,b.name,a.name as author_name from books b JOIN
authors a ON b.author_id=a.id WHERE b.pages > 300", conn);
DataTable dt = new DataTable();
da.Fill(dt);
using (testEntities context = new testEntities())
{
var q = from b in context.Books
join a in context.Authors
on b.Author.Id equals a.Id
where b.Pages > 300
select new
{
bookId = b.Id,
bookName = b.Name,
authorName = a.Name
};
string sql = q.ToTraceString();
CheckSql(sql, SQLSyntax.SimpleJoinWithPredicate);
int i = 0;
foreach (var o in q)
Assert.AreEqual(dt.Rows[i++][0], o.bookId);
Assert.AreEqual(dt.Rows.Count, i);
}
}
示例5: ConversionToLike
public void ConversionToLike()
{
// Generates queries for each LIKE + wildcards case and checks SQL generated.
using (testEntities ctx = new testEntities())
{
// Like 'pattern%'
var q = from c in ctx.Employees where c.FirstName.StartsWith( "B" )
orderby c.FirstName select c;
string query = q.ToTraceString();
CheckSql(query, SQLSyntax.StartsWithTranslatedToLike);
Assert.AreEqual(2, q.Count());
Assert.AreEqual("Barney", q.First().FirstName);
Assert.AreEqual("Betty", q.Skip(1).First().FirstName);
// Like '%pattern%'
q = from c in ctx.Employees where c.FirstName.Contains("r")
orderby c.FirstName select c;
query = q.ToTraceString();
CheckSql(query, SQLSyntax.ContainsTranslatedToLike);
Assert.AreEqual(2, q.Count());
Assert.AreEqual("Barney", q.First().FirstName);
Assert.AreEqual("Fred", q.Skip(1).First().FirstName);
// Like '%pattern'
q = from c in ctx.Employees
where c.FirstName.EndsWith("y")
orderby c.FirstName
select c;
query = q.ToTraceString();
CheckSql(query, SQLSyntax.EndsWithTranslatedToLike);
Assert.AreEqual(3, q.Count());
Assert.AreEqual("Barney", q.First().FirstName);
Assert.AreEqual("Betty", q.Skip(1).First().FirstName);
Assert.AreEqual("Scooby", q.Skip(2).First().FirstName);
}
}
示例6: CanGroupByMultipleColumns
public void CanGroupByMultipleColumns()
{
MySqlDataAdapter adapter = new MySqlDataAdapter(
"SELECT Name, COUNT(Id) as Count FROM Companies GROUP BY Name, NumEmployees, DateBegan", conn);
DataTable table = new DataTable();
adapter.Fill(table);
using (testEntities context = new testEntities())
{
var companies = from c in context.Companies
group c by new { c.Name, c.NumEmployees, c.DateBegan } into cgroup
select new
{
Name = cgroup.Key.Name,
Count = cgroup.Count()
};
string sql = companies.ToTraceString();
CheckSql(sql, SQLSyntax.CanGroupByMultipleColumns);
int i = 0;
foreach (var company in companies)
{
Assert.AreEqual(table.Rows[i][0], company.Name);
Assert.AreEqual(table.Rows[i][1], company.Count);
i++;
}
}
}
示例7: SimpleJoin
public void SimpleJoin()
{
MySqlDataAdapter da = new MySqlDataAdapter(
@"SELECT b.id,b.name,a.name as author_name from books b JOIN
authors a ON b.author_id=a.id", conn);
DataTable dt = new DataTable();
da.Fill(dt);
using (testEntities context = new testEntities())
{
var q = from b in context.Books
join a in context.Authors
on b.Author.Id equals a.Id
select new
{
bookId = b.Id,
bookName = b.Name,
authorName = a.Name
};
int i = 0;
foreach (var o in q)
Assert.AreEqual(dt.Rows[i++][0], o.bookId);
Assert.AreEqual(dt.Rows.Count, i);
}
}
示例8: JoinOfNestedUnionsWithLimit
public void JoinOfNestedUnionsWithLimit()
{
using (testEntities context = new testEntities())
{
var q = context.Books.Include("Author");
q = q.Include("Publisher");
q = q.Include("Publisher.Books");
string sql = q.ToTraceString();
var i = 0;
foreach (var o in q.Where(p => p.Id > 0).OrderBy(p => p.Name).ThenByDescending(p => p.Id).Skip(0).Take(32).ToList())
{
switch (i)
{
case 0:
Assert.AreEqual(5, o.Id);
Assert.AreEqual("Debt of Honor", o.Name);
break;
case 1:
Assert.AreEqual(1, o.Id);
Assert.AreEqual("Debt of Honor", o.Name);
break;
case 4:
Assert.AreEqual(3, o.Id);
Assert.AreEqual("Rainmaker", o.Name);
break;
}
i++;
}
}
}
示例9: UnsignedValues
public void UnsignedValues()
{
using (testEntities context = new testEntities())
{
var row = context.Children.First();
context.Detach(row);
context.Attach(row);
}
}
示例10: FirstSimple
public void FirstSimple()
{
MySqlCommand cmd = new MySqlCommand("SELECT id FROM orders", conn);
int id = (int)cmd.ExecuteScalar();
using (testEntities context = new testEntities())
{
var q = from o in context.Orders
select o;
Order order = q.First() as Order;
Assert.AreEqual(id, order.Id);
}
}
示例11: FirstPredicate
public void FirstPredicate()
{
MySqlCommand cmd = new MySqlCommand("SELECT id FROM orders WHERE freight > 100", conn);
int id = (int)cmd.ExecuteScalar();
using (testEntities context = new testEntities())
{
var q = from o in context.Orders
where o.Freight > 100
select o;
Order order = q.First() as Order;
Assert.AreEqual(id, order.Id);
}
}
示例12: BigCountSimple
public void BigCountSimple()
{
MySqlCommand trueCmd = new MySqlCommand("SELECT COUNT(*) FROM Toys", conn);
object trueCount = trueCmd.ExecuteScalar();
using (testEntities context = new testEntities())
{
string sql = "SELECT VALUE BigCount(t.Id) FROM Toys AS t";
ObjectQuery<Int32> q = context.CreateQuery<Int32>(sql);
foreach (int count in q)
Assert.AreEqual(trueCount, count);
}
}
示例13: 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);
}
}
示例14: YearMonthDay
public void YearMonthDay()
{
using (testEntities context = new testEntities())
{
ObjectQuery<DbDataRecord> q = context.CreateQuery<DbDataRecord>(
@"SELECT c.DateBegan, Year(c.DateBegan), Month(c.DateBegan), Day(c.DateBegan)
FROM Companies AS c WHERE c.Id=1");
foreach (DbDataRecord record in q)
{
Assert.AreEqual(1996, record[1]);
Assert.AreEqual(11, record[2]);
Assert.AreEqual(15, record[3]);
}
}
}
示例15: Bitwise
public void Bitwise()
{
using (testEntities context = new testEntities())
{
ObjectQuery<Int32> q = context.CreateQuery<Int32>("BitwiseAnd(255,15)");
foreach (int i in q)
Assert.AreEqual(15, i);
q = context.CreateQuery<Int32>("BitwiseOr(240,31)");
foreach (int i in q)
Assert.AreEqual(255, i);
q = context.CreateQuery<Int32>("BitwiseXor(255,15)");
foreach (int i in q)
Assert.AreEqual(240, i);
}
}