本文整理汇总了C#中Table.ToSql方法的典型用法代码示例。如果您正苦于以下问题:C# Table.ToSql方法的具体用法?C# Table.ToSql怎么用?C# Table.ToSql使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Table
的用法示例。
在下文中一共展示了Table.ToSql方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Consulta_Zerando_Project_Com_Null
public void Consulta_Zerando_Project_Com_Null()
{
var users = new Table("users");
users.Project(users["name"])
.Where(users["name"].Like("%n"));
string sql1 = "SELECT users.name FROM users WHERE users.name LIKE @users_name_1";
Assert.AreEqual(sql1, users.ToSql());
users.Project(null);
string sql2 = "SELECT * FROM users WHERE users.name LIKE @users_name_1";
Assert.AreEqual(sql2, users.ToSql());
}
示例2: Insert_Usando_Hashtable
public void Insert_Usando_Hashtable()
{
Hashtable hs = new Hashtable();
hs.Add("nome", "george");
hs.Add("data_nascimento", new DateTime(1989, 8, 22));
hs.Add("sexo", "M");
var t_users = new Table("users");
t_users.Insert(hs);
Console.WriteLine(t_users.ToSql());
string sql_expected = "INSERT INTO users(data_nascimento, nome, sexo) "
+"VALUES(@users_data_nascimento_1, @users_nome_1, @users_sexo_1)";
Assert.AreEqual(sql_expected, t_users.ToSql());
}
示例3: Insert_Com_Valor_Nulo
public void Insert_Com_Valor_Nulo()
{
var users = new Table("users");
users.Insert(new { nome="george", idade=Utils.NULL });
string sql_expected = "INSERT INTO users(idade, nome) VALUES(NULL, @users_nome_1)";
Assert.AreEqual(sql_expected, users.ToSql());
}
示例4: Delete_Sem_Where
public void Delete_Sem_Where()
{
var users = new Table("users");
users.Delete();
string sql_expected = "DELETE FROM users";
Assert.AreEqual(sql_expected, users.ToSql());
}
示例5: Update_Com_Where_E_Valor_Nulo
public void Update_Com_Where_E_Valor_Nulo()
{
var users = new Table("users");
users.Where(users["nome"] != null)
.Update(new { idade = Utils.NULL });
string sql_expected = "UPDATE users SET idade=NULL WHERE users.nome IS NOT NULL";
Assert.AreEqual(sql_expected, users.ToSql());
}
示例6: Insert_Simples
public void Insert_Simples()
{
ITable users = new Table("users");
users.Insert(new { nome = "george", data_nascimento = new DateTime(1989, 8, 22), sexo = "M" });
string sql_expected = "INSERT INTO users(data_nascimento, nome, sexo) "+
"VALUES(@users_data_nascimento_1, @users_nome_1, @users_sexo_1)";
Assert.AreEqual(sql_expected, users.ToSql());
}
示例7: Delete_Com_Where
public void Delete_Com_Where()
{
var users = new Table("users");
users.Where(users["idade"] < 18)
.Delete();
string sql_expected = "DELETE FROM users WHERE users.idade < @users_idade_1";
Assert.AreEqual(sql_expected, users.ToSql());
}
示例8: Delete_Com_Where_Complexo
public void Delete_Com_Where_Complexo()
{
var users = new Table("users");
users.Where(users["idade"] < 18 | users["nome"] == null)
.Where(users["ativo"] != null)
.Delete();
string sql_expected = "DELETE FROM users WHERE (users.idade < @users_idade_1) OR (users.nome IS NULL) AND users.ativo IS NOT NULL";
Assert.AreEqual(sql_expected, users.ToSql());
}
示例9: Delete_Com_Where_Muito_Simples
public void Delete_Com_Where_Muito_Simples()
{
var users = new Table("users");
users.Where(users["id"] == 1)
.Delete();
string sql_expected = "DELETE FROM users WHERE users.id = @users_id_1";
Assert.AreEqual(sql_expected, users.ToSql());
Assert.AreEqual(1, users.Params["users_id_1"]);
}
示例10: Consulta_Simples_Com_Disctinct
public void Consulta_Simples_Com_Disctinct()
{
var users = new Table("users");
users.Project(users["nascimento"])
.Where(users["nome"].Like("%g"))
.Distinct();
string sql_expected = "SELECT DISTINCT users.nascimento FROM users WHERE users.nome LIKE @users_nome_1";
Assert.AreEqual(sql_expected, users.ToSql());
}
示例11: Consulta_Com_Order_By
public void Consulta_Com_Order_By()
{
var users = new Table("users");
users.Project(users["name"], users["password"])
.Where(users["active"] == true)
.OrderBy(users["created_at"].Desc, users["name"]);
string sql_expected = "SELECT users.name, users.password FROM users WHERE users.active = @users_active_1 "
+"ORDER BY users.created_at DESC, users.name";
Assert.AreEqual(sql_expected, users.ToSql());
}
示例12: Consulta_Com_Subselect_No_Where
public void Consulta_Com_Subselect_No_Where()
{
var t_users = new Table("tbUsers");
var t_groups = new Table("tbGroups");
t_users.Project(t_users.All)
.Where(t_users["status"] == t_groups.Project(t_groups["status"]).Where(t_groups["id"] == 1));
string sql_expected = "SELECT tbUsers.* FROM tbUsers WHERE tbUsers.status = "
+"(SELECT tbGroups.status FROM tbGroups WHERE tbGroups.id = @tbGroups_id_1)";
Assert.AreEqual(sql_expected, t_users.ToSql());
}
示例13: Update_Sem_Where
public void Update_Sem_Where()
{
ITable users = new Table("users");
users.Update(new
{
ativo=true
});
string sql_expected = "UPDATE users SET [email protected]_ativo_1";
Assert.AreEqual(sql_expected, users.ToSql());
}
示例14: Update_Com_Where_Primeiro
public void Update_Com_Where_Primeiro()
{
var users = new Table("users");
users.Where(users["idade"] > 20)
.Update(new
{
ativo = true,
salario = 500
});
string sql_expected = "UPDATE users SET [email protected]_ativo_1, [email protected]_salario_1 WHERE users.idade > @users_idade_1";
Assert.AreEqual(sql_expected, users.ToSql());
}
示例15: Update_Com_Where_E_Hashtable
public void Update_Com_Where_E_Hashtable()
{
var users = new Table("users");
Hashtable hs = new Hashtable();
hs.Add("superuser", false);
hs.Add("ativo", true);
users.Where(users["salario"] <= 2000)
.Update(hs);
string sql_expected = "UPDATE users SET [email protected]_ativo_1, [email protected]_superuser_1 "+
"WHERE users.salario <= @users_salario_1";
Assert.AreEqual(sql_expected, users.ToSql());
Assert.AreEqual(true, users.Params["users_ativo_1"]);
Assert.AreEqual(false, users.Params["users_superuser_1"]);
}