예제 #1
0
 public LogORMBaseDal()
 {
     tableName   = CurDalParas.TableName;
     primaryKey  = CurDalParas.PrimaryKey;
     skipCols    = CurDalParas.SkipCols;
     updateKeys  = CurDalParas.UpdateKeys;
     deleteKeys  = CurDalParas.DeleteKeys;
     softDelFalg = CurDalParas.SoftDelFalg;
     orderby     = CurDalParas.Orderby;
     conStr      = ComDBFun.GetConnectionString(CurDalParas.DBConStringKey);
     GetBaseDBByDBType();
     CurSqlProvider = SqlProvider.CreateProvider(CurDalParas.CurDatabaseType);
 }
        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);
            }
        }