Esempio n. 1
0
 internal static string GetOperatorTag(MongoOperator mongoOperator)
 {
     return(mongoOperator switch
     {
         MongoOperator.Equals => "eq",
         MongoOperator.NotEquals => "ne",
         MongoOperator.GreaterThan => "gt",
         MongoOperator.GreaterThanOrEqual => "gte",
         MongoOperator.LessThan => "lt",
         MongoOperator.LessThanOrEqual => "lte",
         MongoOperator.Contains => "in",
         MongoOperator.NotContains => "nin",
         MongoOperator.And => "and",
         MongoOperator.Or => "or",
         MongoOperator.Nor => "nor",
         MongoOperator.Not => "not",
         MongoOperator.Exist => "exists",
         MongoOperator.TypeOf => "type",
         MongoOperator.Regex => "regex",
         MongoOperator.Text => "text",
         MongoOperator.RegexOptions => "options",
         MongoOperator.TextSearch => "search",
         MongoOperator.TextSearchLanguage => "language",
         MongoOperator.TextSearchCaseSensitive => "caseSensitive",
         MongoOperator.TextSearchDiacriticSensitive => "diacriticSensitive",
         _ => throw new ArgumentOutOfRangeException(nameof(mongoOperator), mongoOperator, null)
     });
Esempio n. 2
0
        static void Main(string[] args)
        {
            Console.Title = "MongoDBOperator.Test";

            IOperator <Account> customerOperator = new MongoOperator <Account>();


            var account = new Account();

            account.FirstName   = "li";
            account.LastName    = "wen";
            account.Phone       = "13800138000";
            account.Email       = "*****@*****.**";
            account.HomeAddress = new Address
            {
                Address1 = "上海",
                Address2 = "徐汇",
                PostCode = "210001",
                City     = "上海",
                Country  = "中国"
            };

            Console.WriteLine("Create");

            customerOperator.Add(account);



            Console.WriteLine("Read");

            var c = customerOperator.Where(b => b.FirstName == "li").FirstOrDefault();

            Console.WriteLine("Update");

            c.FirstName = "guo li";

            customerOperator.Update(c);

            Console.WriteLine("Delete");

            customerOperator.Delete(c);

            customerOperator.DeleteAll();

            Console.ReadLine();
        }