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