本文整理汇总了C#中Query.ExecuteScalar方法的典型用法代码示例。如果您正苦于以下问题:C# Query.ExecuteScalar方法的具体用法?C# Query.ExecuteScalar怎么用?C# Query.ExecuteScalar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Query
的用法示例。
在下文中一共展示了Query.ExecuteScalar方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSwitchState
public bool GetSwitchState(string nick,string switchtype)
{
if (nick == null)
{
return false;
}
Query qUS = new Query(typeof(tb_User_SwitchEntity));
qUS.AddAttribute(tb_User_SwitchEntity.__STATE);
Query qS = new Query(typeof(tb_AutoSwitchEntity));
Condition cS = qS.GetQueryCondition();
cS.AddEqualTo(tb_AutoSwitchEntity.__SWITCH, switchtype);
Query qU = new Query(typeof(tb_UserEntity));
Condition cU = qU.GetQueryCondition();
cU.AddEqualTo(tb_UserEntity.__NICK, nick);
qUS.AddJoinQuery(tb_User_SwitchEntity.__SWITCH_ID, qS, tb_AutoSwitchEntity.__ID);
qUS.AddJoinQuery(tb_User_SwitchEntity.__USER_ID, qU, tb_UserEntity.__ID);
object state = qUS.ExecuteScalar();
if (state == null)
{
return false;
}
return (bool)state;
}
示例2: Query_Select
public void Query_Select()
{
Query qry = new Query(Product.Schema);
qry.AddWhere("productID", 1);
int pk = (int)qry.ExecuteScalar();
Assert.IsTrue(pk == 1, "Bad Select");
}
示例3: Query_Select
public void Query_Select()
{
Query qry = new Query(Product.Schema);
qry.AddWhere("productID", 1);
int pk = Convert.ToInt32(qry.ExecuteScalar()); // sqlite: Specified cast is not valid.
Assert.IsTrue(pk == 1, "Bad Select");
}
示例4: OmittingOptionalAtWorksInQuery
public void OmittingOptionalAtWorksInQuery()
{
Query query = new Query("SELECT MyParam1 + ' + ' + @MyParam2");
query.Parameters.Add("@MyParam1", typeof (string));
query.Parameters.Add("MyParam2", typeof (string));
query.Parameters["MyParam1"].Value = "MyParam1Value";
query.Parameters["@MyParam2"].Value = "MyParam2Value";
object value = query.ExecuteScalar();
Assert.AreEqual(value, "MyParam1Value + MyParam2Value");
}
示例5: GetContextTotalByUser
public int GetContextTotalByUser(string nick)
{
Query qU = new Query(typeof(tb_UserEntity));
Condition cU = qU.GetQueryCondition();
cU.AddEqualTo(tb_UserEntity.__NICK, nick);
Query qT = new Query(typeof(tb_TraderateContextEntity));
qT.SelectCount(tb_TraderateContextEntity.__ID,"total");
qT.AddJoinQuery(tb_TraderateContextEntity.__USER_ID, qU, tb_UserEntity.__ID);
object o=qT.ExecuteScalar();
return (int)o;
}
示例6: GetSwitchPropertyState
public bool GetSwitchPropertyState(string nick, string switchpro)
{
Query qUS = new Query(typeof(tb_User_SwitchPropertyEntity));
qUS.AddAttribute(tb_User_SwitchPropertyEntity.__STATE);
Query qS = new Query(typeof(tb_SwitchPropertyEntity));
Condition cS = qS.GetQueryCondition();
cS.AddEqualTo(tb_SwitchPropertyEntity.__PRONAME, switchpro);
Query qU = new Query(typeof(tb_UserEntity));
Condition cU = qU.GetQueryCondition();
cU.AddEqualTo(tb_UserEntity.__NICK, nick);
qUS.AddJoinQuery(tb_User_SwitchPropertyEntity.__SWITCHPROERTY_ID, qS, tb_SwitchPropertyEntity.__ID);
qUS.AddJoinQuery(tb_User_SwitchPropertyEntity.__USER_ID,qU,tb_UserEntity.__ID);
object state = qUS.ExecuteScalar();
if (state == null)
{
return false;
}
return (bool)state;
}
示例7: GetTraderContext
public string GetTraderContext(string nick)
{
if (nick == "")
{
return "";
}
Query qU=new Query(typeof(tb_UserEntity));
Condition c=qU.GetQueryCondition();
c.AddEqualTo(tb_UserEntity.__NICK,nick);
Query qT=new Query(typeof(tb_TraderateContextEntity));
qT.AddAttribute(tb_TraderateContextEntity.__CONTEXT);
qT.AddJoinQuery(tb_TraderateContextEntity.__USER_ID,qU,tb_UserEntity.__ID);
object o = qT.ExecuteScalar();
if (o != null)
{
return o.ToString();
}
else
{
return "";
}
}
示例8: QueryParameterChangeTriggersRecompilation
public void QueryParameterChangeTriggersRecompilation()
{
Query query = new Query("SELECT @Param");
query.Parameters.Add("@Param", typeof(string));
query.Parameters["@Param"].Value = "Test";
Assert.AreEqual("Test", query.ExecuteScalar());
query.Parameters.Remove("@Param");
query.Parameters.Add("@Param", typeof(string));
query.Parameters["@Param"].Value = "XXX";
Assert.AreEqual("XXX", query.ExecuteScalar());
}
示例9: DirectConstantInQuery
public void DirectConstantInQuery()
{
Query query = new Query();
query.DataContext.Constants.Add("MyNumberConstant", 42);
query.Text = "SELECT MyNumberConstant";
int expectedValue = Convert.ToInt32(query.DataContext.Constants["MyNumberConstant"].Value);
Assert.AreEqual(expectedValue, query.ExecuteScalar());
}
示例10: NonfoldedConstantsInQuery
public void NonfoldedConstantsInQuery()
{
Query expression = new Query();
expression.Parameters.Add("P1", typeof(DateTime), DateTime.Now);
expression.DataContext.Constants.Add("MyNumberConstant", 42);
expression.Text = "SELECT P1.AddDays(MyNumberConstant)";
DateTime p1 = Convert.ToDateTime(expression.Parameters["P1"].Value);
int myNumberConstant = Convert.ToInt32(expression.DataContext.Constants["MyNumberConstant"].Value);
DateTime expectedValue = p1.AddDays(myNumberConstant);
Assert.AreEqual(expectedValue, expression.ExecuteScalar());
}
示例11: FoldedConstantsInQuery
public void FoldedConstantsInQuery()
{
Query query = new Query();
query.DataContext.Constants.Add("MyStringConstant", "Test");
query.DataContext.Constants.Add("MyNumberConstant", 42);
query.Text = "SELECT MyStringConstant.Length * MyNumberConstant";
int expectedValue = Convert.ToString(query.DataContext.Constants["MyStringConstant"].Value).Length *
Convert.ToInt32(query.DataContext.Constants["MyNumberConstant"].Value);
Assert.AreEqual(expectedValue, query.ExecuteScalar());
}
示例12: GetOrderId
/// <summary>
/// Gets the order id.
/// </summary>
/// <param name="userName">Name of the user.</param>
/// <returns></returns>
public int GetOrderId(string userName)
{
int orderId = 0;
Query query = new Query(Order.Schema).
AddWhere(Order.Columns.UserName, userName).
AddWhere(Order.Columns.OrderStatusDescriptorId, (int)OrderStatus.NotProcessed);
query.SelectList = Order.Columns.OrderId;
object result = query.ExecuteScalar();
if(result != null) {
int.TryParse(result.ToString(), out orderId);
}
return orderId;
}