示例#1
0
        static void Main(string[] args)
        {
            MongoCRUD db = new MongoCRUD("AddressBook");
            //1. To insert simple model objects
            //db.InsertRecord("Users", new PersonModel { FirstName = "Mary", LastName = "Jones" });

            //2. To insert complex model objects
            //PersonModel person = new PersonModel()
            //{
            //    FirstName = "Joe",
            //    LastName = "Smith",
            //    PrimaryAddress = new AddressModel()
            //    {
            //        StreetAddress = "101 Oak Street",
            //        City = "Scranton",
            //        State = "PA",
            //        ZipCode = "11100"
            //    }
            //};
            //db.InsertRecord("Users", person);


            //3. To read records (Simpler to 'select * from db' in SQL database
            var records = db.LoadRecords <PersonModel>("Users");

            foreach (var item in records)
            {
                Console.WriteLine($"{item.Id}: {item.FirstName}: {item.LastName} ");
                if (item.PrimaryAddress != null)
                {
                    Console.WriteLine(item.PrimaryAddress.City);
                }
                Console.WriteLine();
            }


            //4. To read single record depending upon ID
            var userRecord = db.LoadRecordById <PersonModel>("Users", new Guid("8dcc7170-c154-407a-9a4e-f335c8fbd46e"));

            //5. To update the single record
            userRecord.DateOfBirth = new DateTime(1982, 10, 31, 0, 0, 0, DateTimeKind.Utc);
            db.UpsertRecord("Users", userRecord.Id, userRecord);

            //6. To delete record
            db.DeleteRecord <PersonModel>("Users", userRecord.Id);

            //7. To read data in different Model Object
            var nameRecords = db.LoadRecords <NameModel>("Users");

            foreach (var item in records)
            {
                Console.WriteLine($"{item.Id}: {item.FirstName}: {item.LastName} ");
                Console.WriteLine();
            }

            Console.ReadLine();
        }
示例#2
0
        private static void RUD_Person(MongoCRUD db, List <PersonModel> recs)
        {
            var oneRec = db.LoadRecordById <PersonModel>("Users", recs[2].Id);

            oneRec.DateOfBirth = new DateTime(2003, 12, 28, 0, 0, 0, DateTimeKind.Utc);
            db.UpsertRecord("Users", oneRec.Id, oneRec);

            db.DeleteRecord <PersonModel>("Users", oneRec.Id);
        }
示例#3
0
        static void Main(string[] args)
        {
            // if not available it will actually create one!  Can't do this in SQL.
            MongoCRUD db = new MongoCRUD("AddressBook");

            var oneRecord = db.LoadRecordById <PersonModel>("Users", new Guid("f33c2b5e-4eaf-4b4f-b1f6-d3b257ea30a3"));

            oneRecord.DateOfBirth = new DateTime(1982, 10, 31, 0, 0, 0, DateTimeKind.Utc);
            db.UpsertRecord("Users", oneRecord.Id, oneRecord);

            Console.ReadLine();
        }