MongoDB storage generic list set

Source: Internet
Author: User
   Protected     Virtual  Configurationbuilder getconfiguration ()
{
VaR Builder = New Configurationbuilder ();
Builder. readconnectionstringfromappsettings ( " Tests " );
Return Builder;
}
// Data ing Class (Key, value)
Class Listinfo
{
Public Int Key { Get ; Set ;}
Public Object Value { Get ; Set ;}
}
Static Void Main ( String [] ARGs)
{
VaR config = New Configurationbuilder ();
// 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 = New Mongo (config. buildconfiguration ()))
{
Mongo. Disconnect ();
Mongo. Connect ();
Try
{
VaR DB = Mongo. getdatabase ( " Testdb " );
VaR collection = DB. getcollection < Listinfo > ();
// To add information, you can open comments.
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 + = " No: " + Listd [ 1 ];
List < Document > Items = (Listd [ 2 ] As List < Document > );
Foreach (VAR Item1 In Items)
{
VaR item2 = Item1.tolist ()[ 1 ]. Value;
Showinfo + = " Name: " + Item2;
}

}
Console. writeline (showinfo );
}
Catch {}
}
Console. readkey ();
}

# Region Set Information

# Region Add information to combine
Private Static Listinfo bindvendor ()
{
Vendor Square = New Vendor ()
{
Vendorid = 2 ,
Vendorname = " Xijiao Auto Parts City " ,
Itemid = Datetime. Now. Second
};
List < Vendor > List = New List < Vendor > ();
List. Add (square );
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.