本文整理汇总了C#中BLToolkit.Data.DbManager.SetSpCommand方法的典型用法代码示例。如果您正苦于以下问题:C# DbManager.SetSpCommand方法的具体用法?C# DbManager.SetSpCommand怎么用?C# DbManager.SetSpCommand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BLToolkit.Data.DbManager
的用法示例。
在下文中一共展示了DbManager.SetSpCommand方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SprocParameterPrefixShouldBeSpecifiedManuallyWhenItIsNotSet
public void SprocParameterPrefixShouldBeSpecifiedManuallyWhenItIsNotSet()
{
using (var db = new DbManager(ProviderName.MySql))
{
var person = db.SetSpCommand("GetPersonById", db.Parameter("?_ID", 1)).ExecuteObject<Person>();
Assert.IsNotNull(person);
var person2 = db.SetSpCommand(
"GetPersonByName",
db.Parameter("?_lastName", person.LastName),
db.Parameter("?_firstName", person.FirstName))
.ExecuteObject<Person>();
Assert.IsNotNull(person2);
}
}
示例2: GetPersonListSproc
IList<Person> GetPersonListSproc()
{
using (DbManager db = new DbManager())
{
return db
.SetSpCommand("Person_SelectAll")
./*[a]*/ExecuteList<Person>()/*[/a]*/;
}
}
示例3: GetCustomPersonList
void GetCustomPersonList(IList list)
{
using (DbManager db = new DbManager())
{
db
.SetSpCommand("Person_SelectAll")
./*[a]*/ExecuteList(list, typeof(Person))/*[/a]*/;
}
}
示例4: GetByUserId
public List<LogEntity> GetByUserId(int userId)
{
using (var db = new DbManager())
{
return db
.SetSpCommand("GetLogsByUserId", userId)
.ExecuteList<LogEntity>();
}
}
示例5: GetById
public LogEntity GetById(int id)
{
using (var db = new DbManager())
{
return db
.SetSpCommand("GetLogById", id)
.ExecuteObject<LogEntity>();
}
}
示例6: GetAll
public List<LogEntity> GetAll()
{
using (var db = new DbManager())
{
return db
.SetSpCommand("GetAllLogs")
.ExecuteList<LogEntity>();
}
}
示例7: GetPersonList
// Select a person list.
//
public IList<Person> GetPersonList()
{
using (DbManager db = new DbManager())
{
return db
./*[a]*/SetSpCommand/*[/a]*/("Person_SelectAll")
.ExecuteList<Person>();
}
}
示例8: GetPersonSproc2
Person GetPersonSproc2(int id)
{
using (DbManager db = new DbManager())
{
return db
.SetSpCommand("Person_SelectByKey", id)
./*[a]*/ExecuteObject<Person>()/*[/a]*/;
}
}
示例9: ReturnValueTest2
public void ReturnValueTest2()
{
using (DbManager db = new DbManager())
{
int n = db
.SetSpCommand("Scalar_ReturnParameter")
.ExecuteScalar<int>(ScalarSourceType.ReturnValue);
Assert.AreEqual(12345, n);
}
}
示例10: GetPersonByID2
public Person GetPersonByID2(int id)
{
using (DbManager db = new DbManager())
{
// Pass a parameter using the [b]params[/b] parameter of the SetSpCommand method.
//
return db
./*[a]*/SetSpCommand/*[/a]*/("Person_SelectByKey", /*[a]*/id/*[/a]*/)
.ExecuteObject<Person>();
}
}
示例11: GetPersonByID1
// Select a person.
//
public Person GetPersonByID1(int id)
{
using (DbManager db = new DbManager())
{
// Pass a parameter using the [b]Parameter[/b] method.
//
return db
./*[a]*/SetSpCommand/*[/a]*/("Person_SelectByKey",
db./*[a]*/Parameter/*[/a]*/("@id", id))
.ExecuteObject<Person>();
}
}
示例12: ParameterPrefixTest
public void ParameterPrefixTest()
{
var oldPrefix = MySqlDataProvider.SprocParameterPrefix;
MySqlDataProvider.SprocParameterPrefix = "_";
try
{
using (var db = new DbManager(ProviderName.MySql))
{
var person = db.SetSpCommand("GetPersonById", db.Parameter("?ID", 1)).ExecuteObject<Person>();
Assert.IsNotNull(person);
var person2 = db.SetSpCommand("GetPersonByName", db.CreateParameters(person)).ExecuteObject<Person>();
Assert.IsNotNull(person2);
Assert.AreEqual(person, person2);
}
}
finally
{
MySqlDataProvider.SprocParameterPrefix = oldPrefix;
}
}
示例13: Test
public void Test()
{
List<Person> list = new List<Person>
{
new Person { FirstName = "John", LastName = "Smith", Gender = Gender.Male },
new Person { FirstName = "Jane", LastName = "Smith", Gender = Gender.Female }
};
using (DbManager db = new DbManager())
{
db.BeginTransaction();
// Prepare command.
//
db
.SetSpCommand("Person_Insert",
db.CreateParameters(list[0]))
./*[a]*/Prepare/*[/a]*/();
// Insert.
//
foreach (Person person in list)
{
db./*[a]*/AssignParameterValues/*[/a]*/(person);
db.ExecuteNonQuery();
}
// Check the result.
//
list = db
.SetCommand(
"SELECT * FROM Person WHERE LastName = @lastName",
db.Parameter("@lastName", "Smith"))
.ExecuteList<Person>();
Assert.GreaterOrEqual(2, list.Count);
// Cleanup.
//
db
.SetCommand(
"DELETE FROM Person WHERE LastName = @lastName",
db.Parameter("@lastName", "Smith"))
.ExecuteNonQuery();
db.CommitTransaction();
}
}
示例14: Main
static void Main(string[] args)
{
using (var db = new DbManager())
{
db.SetSpCommand(""); // ok
db.SetInsertCommand(""); // ok
db.SetUpdateCommand(""); // ok
db.Prepare(); // ok
db.ExecuteNonQuery(); // ok
db.SetCommand(""); // ERROR:
// error CS0584: Internal compiler error: Object reference not set to an instance of an object
// error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement
}
}
示例15: ReturnValueTest
public void ReturnValueTest()
{
using (DbManager db = new DbManager())
{
/*
* CREATE Function Scalar_ReturnParameter()
* RETURNS int
* AS
* BEGIN
* RETURN 12345
* END
*/
int n = db
.SetSpCommand("Scalar_ReturnParameter")
./*[a]*/ExecuteScalar/*[/a]*/<int>(/*[a]*/ScalarSourceType.ReturnValue/*[/a]*/);
Assert.AreEqual(12345, n);
}
}