本文整理汇总了C#中DBConnection.OpenQuery方法的典型用法代码示例。如果您正苦于以下问题:C# DBConnection.OpenQuery方法的具体用法?C# DBConnection.OpenQuery怎么用?C# DBConnection.OpenQuery使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBConnection
的用法示例。
在下文中一共展示了DBConnection.OpenQuery方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadMessages
void LoadMessages()
{
if (game == null)
return;
using (var db = new DBConnection())
{
ViewBag.Messages = new List<Message>();
using (var messages = db.OpenQuery(String.Format("select m.id as id, to_id, from_id, fromAccount.name fromName, text, time from message as m join account as fromAccount on m.from_id = fromAccount.id where to_id = {0} order by id desc limit 150", -game.Id)))
{
while (messages.Read())
{
var newMessage = new Message() { Id = (int)messages["id"], SourceId = (int)messages["from_id"], SourceName = (string)messages["fromName"], Text = messages["text"].ToString(), Sent = Utility.FromUnixTimestamp((int)messages["time"]) };
ViewBag.Messages.Add(newMessage);
}
}
}
}
示例2: LoadMessages
List<Message> LoadMessages(DBConnection db, int toId)
{
var result = new List<Message>();
using (var messages = db.OpenQuery(String.Format("select m.id as id, to_id, from_id, fromAccount.name fromName, toAccount.name toName, text, time from message as m join account as fromAccount on m.from_id = fromAccount.id join account as toAccount on m.to_id = toAccount.id where to_id = {0} or from_id = {0} order by id desc limit 150", toId)))
{
var count = 0;
while (messages.Read())
{
var destinationId = (int)messages["to_id"];
if (destinationId > 0)
{
var newMessage = new Message() { Id = (int)messages["id"], SourceId = (int)messages["from_id"], SourceName = (string)messages["fromName"], DestinationId = destinationId, DestinationName = (string)messages["toName"], Text = messages["text"].ToString(), Sent = Utility.FromUnixTimestamp((int)messages["time"]) };
result.Add(newMessage);
count++;
if (count >= 100)
break;
}
}
}
return result;
}