亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

MongoDB存儲泛型List<User>集合

發布時間:2020-06-03 09:45:07 來源:網絡 閱讀:3304 作者:duoku 欄目:MongoDB數據庫

 protected virtual MongoConfigurationBuilder GetConfiguration()

        {
            var builder = new MongoConfigurationBuilder();
            builder.ReadConnectionStringFromAppSettings("tests");
            return builder;
        }
        //數據映射類(key,value)
        class ListInfo
        {
            public int key { get; set; }
            public object value { get; set; }
        }
        static void Main(string[] args)
        {
            var config = new MongoConfigurationBuilder();
            // COMMENT OUT FROM HERE
            config.Mapping(mapping =>
            {
                mapping.DefaultProfile(profile =>
                {
                    profile.SubClassesAre(t => t.IsSubclassOf(typeof(ListInfo)));
                });
                mapping.Map<ListInfo>();
            });

            config.ConnectionString("Server=127.0.0.1");
            using (Mongo mongo = new Mongo(config.BuildConfiguration()))
            {
                mongo.Disconnect();
                mongo.Connect();
                try
                {
                    var db = mongo.GetDatabase("TestDb");
                    var collection = db.GetCollection<ListInfo>();
                    //添加信息 需要就可以打開注釋
                    ListInfo list = BindVendor();
                    collection.Save(list);
                    var coll = db.GetCollection("ListInfo");
                    var info = coll.Find(new Document().Add("key", 7888)).Documents.ToList();
                    string showinfo = "";
                    foreach (Document item in info)
                    {

                        var listd = item.Values.ToList();
                        showinfo += "編號:" + listd[1];
                        List<Document> items = (listd[2] as List<Document>);
                        foreach (var item1 in items)
                        {
                            var item2 = item1.ToList()[1].Value;
                            showinfo += "名稱:" + item2;
                        }

                    }
                    Console.WriteLine(showinfo);
                }
                catch { }
            }
            Console.ReadKey();
        }

        #region 集合信息

        #region 添加信息到結合
        private static ListInfo BindVendor()
        {
            vendor square = new vendor()
            {
                vendorid = 2,
                vendorname = "西郊汽配城",
                itemid = DateTime.Now.Second
            };
            List<vendor> list = new List<vendor>();
            list.Add(square);
            ListInfo listinfo = new ListInfo()
            {
                key = 7888,
                value = list
            };
            return listinfo;
        }
        #endregion
        #region 實體類
        class vendor
        {
            public int vendorid { get; set; }
            public string vendorname { get; set; }
            public int itemid { get; set; }
        }
        #endregion

        #endregion

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

花莲市| 绥阳县| 江安县| 贡嘎县| 红河县| 射洪县| 虞城县| 韶山市| 吉木萨尔县| 家居| 五寨县| 拜泉县| 双桥区| 安泽县| 龙州县| 兰坪| 太原市| 永丰县| 中宁县| 新平| 平陆县| 丰镇市| 榆社县| 阿鲁科尔沁旗| 丁青县| 高要市| 汕尾市| 东山县| 昌黎县| 阿拉善盟| 巴楚县| 陆河县| 常熟市| 墨脱县| 岱山县| 建水县| 颍上县| 美姑县| 信丰县| 德昌县| 探索|