当前位置: 首页>>代码示例>>C#>>正文


C# DBConnection.OpenQuery方法代码示例

本文整理汇总了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);
                    }
                }
            }
        }
开发者ID:AdmiralPotato,项目名称:ggj2013,代码行数:19,代码来源:GameController.cs

示例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;
        }
开发者ID:AdmiralPotato,项目名称:ggj2013,代码行数:23,代码来源:HomeController.cs


注:本文中的DBConnection.OpenQuery方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。