-
Notifications
You must be signed in to change notification settings - Fork 1.3k
7.Ado
sunkaixuan edited this page May 4, 2019
·
13 revisions
//sql
var dt=db.Ado.GetDataTable("select * from table where id=@id and name=@name",new List<SugarParameter>(){
new SugarParameter("@id",1),
new SugarParameter("@name",2)
});
//sql
var dt=db.Ado.GetDataTable("select * from table where id=@id and name=@name",new{id=1,name=2});
//Stored Procedure
var dt2 = db.Ado.UseStoredProcedure().GetDataTable("sp_school",new{name="张三",age=0});// GetInt SqlQuery<T> 等等都可以用
var nameP= new SugarParameter("@name", "张三");
var ageP= new SugarParameter("@age", null, true);//isOutput=true
var dt2 = db.Ado.UseStoredProcedure().GetDataTable("sp_school",nameP,ageP);
name | description | return type |
---|---|---|
SqlQuery< T > | Query 1 collection,T can be entity or dynamic. | List |
SqlQuery<T,T2> | Query 2 collection | Tuple<List, List> |
SqlQuerySingle | first row | T |
GetDataTable | Query a collection | DataTable |
GetDataReader | Read while using | DataReader |
GetDataSetAll | Query multiple result sets | DataSet |
ExecuteCommand | Number of affected rows | int |
GetScalar | first row first column | object |
GetString | first row first column | string |
GetInt | first row first column | int |
GetLong | first row first column | long |
GetDouble | first row first column | Double |
GetDecimal | first row first column | Decimal |
GetDateTime | first row first column | DateTime |
var result = db.Ado.UseTran(() =>
{
var beginCount = db.Queryable<Student>().Count();
db.Ado.ExecuteCommand("delete student");
//throw new Exception("error haha"); 测试代码
});
// result.ErrorException
// result.IsSuccess
var result2 = db.Ado.UseTran<List<Student>>(() =>
{
return db.Queryable<Student>().ToList();
});
// result.ErrorException
// result.IsSuccess
// result.Data
try
{
db.Ado.BeginTran();
...
db.Ado.CommitTran();
}
catch (Exception ex)
{
db.Ado.RollbackTran();
throw ex;
}
db.Ado.CommandTimeOut=30;//Setting timeout time