예제 #1
0
        public OrmSecondEntityAccessor()
        {
            string            connectionString = ConfigurationManager.ConnectionStrings["SQLServerCE"].ConnectionString;
            string            providerName     = ConfigurationManager.ConnectionStrings["SQLServerCE"].ProviderName;
            DbProviderFactory factory          = DbProviderFactories.GetFactory(providerName);

            orm = new MyORM(factory, connectionString, typeof(SecondEntity));
        }
예제 #2
0
        public FormMain()
        {
            InitializeComponent();

            User us = new User("Vasya", "Pupkin", User.MaleFemale.Male, new DateTime(1980, 01, 01), "*****@*****.**", "qwerty");

            MyORM.AddUser(us);

            User us1 = new User("Pavlic", "Marozov", User.MaleFemale.Male, new DateTime(1928, 05, 15), "*****@*****.**", "qwerty");

            MyORM.AddUser(us1);

            User us2 = new User("Anka", "Mashinganner", User.MaleFemale.Female, new DateTime(1885, 06, 28), "*****@*****.**", "qwerty");

            MyORM.AddUser(us2);

            Author au = new Author("Jack", "London", Body.MaleFemale.Male, new DateTime(1875, 07, 14), new DateTime(1910, 05, 10));

            MyORM.AddAuthor(au);

            Author au1 = new Author("Boris", "Akunin", Body.MaleFemale.Male, new DateTime(1962, 08, 14));

            MyORM.AddAuthor(au1);

            Author au2 = new Author("Anna", "Ahmatova", Body.MaleFemale.Female, new DateTime(1910, 10, 20), new DateTime(1968, 05, 20));

            MyORM.AddAuthor(au2);

            List <Author> Authors = new List <Author>();

            Authors.Add(au);
            Authors.Add(au1);
            Authors.Add(au2);

            Book Book = new Book("Robinzon Cruzo", Book.Availability.Available, Authors);

            MyORM.AddBook(Book, Authors);

            User foundUs = MyORM.GetUser(19);

            User foundUs1 = MyORM.GetUser(30);

            User foundUs2 = MyORM.GetUser("Anka", "Mashinganner");

            List <Author> aut = MyORM.GetBookAuthors(9);

            List <Book> bk = MyORM.GetBooksOfAthor(MyORM.GetAuthor(14));

            Book Book1 = MyORM.GetBook("Robinzon Cruzo");
        }
예제 #3
0
        public List <TResult> Executes <TResult>(Expression expression)
        {
            //string sql = ExpressionTreeToSql.GetSql<TResult>(expression);
            var sql = SqlBulider <TResult> .GetSql(SqlType.Select);

            var vistor = new SqlVistor();

            vistor.Visit(expression);
            sql += vistor.GetWhereSql();

            Console.WriteLine(sql);

            var result = new MyORM <TResult>().GetList(sql);

            return(result);
        }
예제 #4
0
        static void Main(string[] args)
        {
            /* var persons = new List<Person>
                              {
                                  new Person("Иванов", "Иван", "Иванович", 20),
                                  new Person("Сергеев", "Иван", "Иванович", 22),
                                  new Person("Антонов", "Иван", "Петрович", 21),
                                  new Person("Свиридова", "Мария", "Ивановна", 18),
                                  new Person("Романов", "Игорь", "Иванович", 25),
                                  new Person("Борисов", "Иван", "Ильич", 27),
                                  new Person("Телегин", "Олег", "Иванович", 22),
                                  new Person("Юрьев", "Иван", "Иванович", 24),
                                  new Person("Сушкин", "Артём", "Иванович", 25),
                                  new Person("Ломакина", "Ирина", "Юрьевна", 24),
                                  new Person("Петрова", "Светлана", "Васильевна", 23),
                                  new Person("Зверева", "Анна", "Леонидовна", 26)
                              };*/

            //IDataAccessor accessor = new FileDataAccessor("data", persons);
            //IDataAccessor accessor = new ListDataAccessor(persons);
            IDataAccessor<ContactInfo> accessor = new MyORM<ContactInfo>();
            var people = accessor.GetAll();
            foreach (var person in people)
            {
                Console.WriteLine(person.ToString());
            }

            Console.WriteLine();
            Console.Write("Введите Id для поиска:");
            int id = int.Parse(Console.ReadLine());
            var pers = accessor.GetById(id);

            Console.WriteLine(pers.ToString());

            Console.WriteLine();

            accessor.DeleteById(id);
            people = accessor.GetAll();
            foreach (var person in people)
            {
                Console.WriteLine(person.ToString());
            }
            Console.WriteLine();

            Console.Write("Введите фамилию:");
            var address = Console.ReadLine();
            Console.Write("Введите имя:");
            var phone = Console.ReadLine();
            Console.Write("Введите отчество:");
            var email = Console.ReadLine();
            Console.Write("Введите возраст:");
            var age = int.Parse(Console.ReadLine());
            accessor.Insert(new ContactInfo(){Address = address, Phone = phone, Email = email});
            people = accessor.GetAll();
            foreach (var person in people)
            {
                Console.WriteLine(person.ToString());
            }
               /* Console.WriteLine("Первоначальное состояние: ");
            Print(accessor);

            var newPerson = new Person("Дубина", "Сергей", "Митрофанович", 40);
            accessor.Insert(newPerson);
            Console.WriteLine("Добавленный элемент: ");
            Console.WriteLine(accessor.GetById("Дубина").ToString());

            accessor.DeleteById("Зверева");
            Console.WriteLine("После удаления Зверевой: ");
            Print(accessor);*/
            Console.ReadKey();
        }
예제 #5
0
        static void Main(string[] args)
        {
            // 配置数据库连接
            var configuration = new ConfigurationBuilder()
                                .AddJsonFile("appsettings.json")
                                .Build();

            SqlConnectionPool.Init(configuration["ConnectionsStr:Write"], configuration.GetSection("ConnectionsStr").GetSection("Read").GetChildren().Select(a => a.Value).ToList());

            {
                var blogDal = new MyORM <Blogs>();
                for (int i = 0; i < 10; i++)
                {
                    var blog = blogDal.Find(1);
                }
            }

            {
                var blogDal = new MyORM <Blogs>();
                blogDal.Insert(new Blogs
                {
                    Name         = "测试ORM插入",
                    CreateTime   = DateTime.Now,
                    ModifiedTime = DateTime.Now,
                    Url          = "www.google.com",
                    IsDeleted    = false
                });

                //for (int i = 1; i < 100; i++)
                //{

                //    var blog = blogDal.Find(1004);
                //    if (blog == null)
                //        Console.WriteLine($"第{i}未获取到");
                //    else
                //        break;
                //    Thread.Sleep(500);
                //}
                //Console.WriteLine("获取到了");
            }

            {
                //var blogDal = new MyORM<Blogs>();
                //var blog = blogDal.Find(2);
                //blog.Name += "123";
                //blogDal.Update(blog);
            }

            {
                //var blogDal = new MyORM<Blogs>();
                //blogDal.Delete(2);
            }

            {
                //var blogDal = new MyORM<Blogs>();
                //var blog = blogDal.Find(3);
                //blog.Name += "123";
                //string name = "123";
                //blogDal.UpdateCondition(new Blogs { IsDeleted = true }, a => a.Name == name && a.IsDeleted == true);
            }

            {
                //var name = Console.ReadLine();
                //var isDelete = Console.ReadLine() == "Y";

                //var query = new MyORM<Blogs>().Table;
                //if (!string.IsNullOrEmpty(name))
                //    query = query.Where(a => a.Name == name);
                //query = query.Where(a => a.IsDeleted == isDelete);
                //var list = query.ToList();
                //foreach (var item in list)
                //{
                //    Console.WriteLine(item.Name + "-" + item.CreateTime);
                //}
            }

            Console.ReadKey();
        }