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


C# QueryDocument.Clear方法代码示例

本文整理汇总了C#中MongoDB.Driver.QueryDocument.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# QueryDocument.Clear方法的具体用法?C# QueryDocument.Clear怎么用?C# QueryDocument.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MongoDB.Driver.QueryDocument的用法示例。


在下文中一共展示了QueryDocument.Clear方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: getOrder

        /// <summary>
        /// This method retrieves a order.
        /// </summary>
        /// <param name="id">Unique ID of order to retrieve</param>
        /// <returns>order object</returns>
        public Order getOrder(Int32 id)
        {
            dLog.Info("Entering method getOrder | ID: " + id);
            Order o = new Order();

            try
            {
                MongoServer server = MongoServer.Create();
                MongoDatabase db = server.GetDatabase("neatoBurrito");
                //MongoCredentials credentials = new MongoCredentials("username", "password");
                //MongoDatabase salaries = server.GetDatabase("salaries", credentials);

                using (server.RequestStart(db))
                {
                    MongoCollection<BsonDocument> coll = db.GetCollection("order");
                    var query = new QueryDocument("id", id);

                    BsonDocument myDoc = coll.FindOne(query);

                    //ensure we were passed a valid object before attempting to read
                    if (myDoc != null)
                    {
                        dLog.Debug("myDoc: " + myDoc.ToString());

                        #region Read Order Fields
                        o.id = id;
                        o.isComplete = myDoc["isComplete"].AsBoolean;
                        o.isSubmitted = myDoc["isSubmitted"].AsBoolean;
                        o.orderDate = myDoc["orderDate"].AsDateTime;
                        o.totalCost = Decimal.Parse(myDoc["totalCost"].AsString);
                        #endregion

                        //get burritos
                        dLog.Debug("Getting burritos");
                        coll = db.GetCollection("burrito");
                        query.Clear();
                        query.Add("orderID", id);
                        MongoCursor cur = coll.Find(query);

                        o.burritos = new List<Burrito>();

                        foreach (var doc in cur)
                        {
                            myDoc = (BsonDocument)doc;
                            Burrito b = new Burrito();

                            //cleaner but too many extra queries this way
                            //o.burritos.Add(burritoSvc.getBurrito(myDoc["id"].AsInt32));

                            #region Read burrito Fields
                            b.id = id;
                            b.Beef = myDoc["beef"].AsBoolean;
                            b.BlackBeans = myDoc["blackBeans"].AsBoolean;
                            b.BrownRice = myDoc["brownRice"].AsBoolean;
                            b.Chicken = myDoc["chicken"].AsBoolean;
                            b.ChiliTortilla = myDoc["chiliTortilla"].AsBoolean;
                            b.Cucumber = myDoc["cucumber"].AsBoolean;
                            b.FlourTortilla = myDoc["flourTortilla"].AsBoolean;
                            b.Guacamole = myDoc["guacamole"].AsBoolean;
                            b.HerbGarlicTortilla = myDoc["herbGarlicTortilla"].AsBoolean;
                            b.Hummus = myDoc["hummus"].AsBoolean;
                            b.JalapenoCheddarTortilla = myDoc["jalapenoCheddarTortilla"].AsBoolean;
                            b.Jalapenos = myDoc["jalapenos"].AsBoolean;
                            b.Lettuce = myDoc["lettuce"].AsBoolean;
                            b.Onion = myDoc["onion"].AsBoolean;
                            b.orderID = myDoc["orderID"].AsInt32;
                            b.PintoBeans = myDoc["pintoBeans"].AsBoolean;
                            b.Price = Decimal.Parse(myDoc["price"].AsString);
                            b.SalsaPico = myDoc["salsaPico"].AsBoolean;
                            b.SalsaSpecial = myDoc["salsaSpecial"].AsBoolean;
                            b.SalsaVerde = myDoc["salsaVerde"].AsBoolean;
                            b.TomatoBasilTortilla = myDoc["tomatoBasilTortilla"].AsBoolean;
                            b.Tomatoes = myDoc["tomatoes"].AsBoolean;
                            b.WheatTortilla = myDoc["wheatTortilla"].AsBoolean;
                            b.WhiteRice = myDoc["whiteRice"].AsBoolean;
                            #endregion

                            o.burritos.Add(b);
                        }
                    }
                    dLog.Debug("Finishing setting order");
                }
            }
            catch (Exception e2)
            {
                dLog.Error("Exception in getOrder: " + e2.Message + "\n" + e2.StackTrace);
                o = new Order();
            }
            finally
            {
                //using statement above already calls RequestDone()
            }

            return o;
        }
开发者ID:bloomj,项目名称:BurritoPOS_CSharp,代码行数:100,代码来源:OrderSvcMongoImpl.cs


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