Beispiel #1
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            Manager.dbProvider = OrmProvider.CreateOrmProvider();
        }
        static void Main(string[] args)
        {
            //生成简单查询脚本
            var sqlProvider = SqlProvider.CreateProvider();

            var sql = sqlProvider.Select("username", "realname", "age")
                      .From("sys_user").Where(new KeyValue()
            {
                Name  = "username",
                Value = "bouyei"
            }).SqlString;

            //结果:Select username,realname,age From sys_user Where username='******'

            ////ado.net 使用例子
            string      connectionString = ConfigurationManager.ConnectionStrings["DbConnection"].ConnectionString;
            AdoProvider dbProvider       = AdoProvider.CreateProvider(connectionString, ProviderType.SqlServer);
            var         adort            = dbProvider.Query(new DbExecuteParameter()
            {
                CommandText = "select * from [user]"
            });


            DataTable dt  = new DataTable();
            var       qrt = dbProvider.QueryToTable(new DbExecuteParameter("select * from [user]"), dt);

            //entity framework 使用例子
            IOrmProvider ormProvider = OrmProvider.CreateProvider("DbConnection");

            try
            {
                User    item = ormProvider.GetById <User>(1);
                UserDto ud   = new UserDto()
                {
                    UserName = "******"
                };

                var query = ormProvider.Query <User>().FirstOrDefault();

                //使用mapper修改对象
                EntityMapper.MapTo <UserDto, User>(ud, item);
                ormProvider.Update(item);
                //保存修改
                int rt = ormProvider.SaveChanges();
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
            }
        }