In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Protected virtual MongoConfigurationBuilder GetConfiguration ()
{
Var builder = new MongoConfigurationBuilder ()
Builder.ReadConnectionStringFromAppSettings ("tests")
Return builder
}
/ / data mapping class (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 ()
});
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 ()
/ / you can open comments if you need to add information.
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 + = "number:" + listd [1]
List items = (listd [2] as List)
Foreach (var item1 in items)
{
Var item2 = item1.ToList () [1] .value
Showinfo + = "name:" + item2
}
}
Console.WriteLine (showinfo)
}
Catch {}
}
Console.ReadKey ()
}
# region Collection Information
# region add information to the combination
Private static ListInfo BindVendor ()
{
Vendor square = new vendor ()
{
Vendorid = 2
Vendorname = "West suburb Auto parts City"
Itemid = DateTime.Now.Second
}
List list = new List ()
List.Add (square)
ListInfo listinfo = new ListInfo ()
{
Key = 7888
Value = list
}
Return listinfo
}
# endregion
# region entity Class
Class vendor
{
Public int vendorid {get; set;}
Public string vendorname {get; set;}
Public int itemid {get; set;}
}
# endregion
# endregion
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.