Exemplo n.º 1
0
 public bool Execute <T>(string sql, IList <Parameter> parameters = null, int timeout = 15) where T : class, new()
 {
     using (IOrm orm = this.orm)
     {
         return(orm.Execute(new SqlCommand(sql, parameters, timeout)));
     }
 }
Exemplo n.º 2
0
 public Database(IDbConnection dbConnection, IOrm orm)
 {
     Check.Argument.IsNotNull(dbConnection, "dbConnection");
     this.dbConnection = dbConnection;
     Check.Argument.IsNotNull(orm, "dataAccessConnection");
     this.orm = orm;
 }
Exemplo n.º 3
0
 public bool Execute(IList <SqlCommand> unitOfWorks)
 {
     using (IOrm connection = this.orm)
     {
         return(connection.Execute(unitOfWorks));
     }
 }
Exemplo n.º 4
0
 public IList <T> Select <T>(string sql, IList <Parameter> parameters = null, int timeout = 15) where T : class, new()
 {
     using (IOrm orm = this.orm)
     {
         return(orm.Select <T>(new SqlCommand(sql, parameters, timeout), CustomMapper.Resolve <T>()).ToList());
     }
 }
Exemplo n.º 5
0
 public IList <T> Select <T>(Expression <Func <T, bool> > expression, int timeout = 15) where T : class, new()
 {
     using (IOrm orm = this.orm)
     {
         SqlCommand result = DynamicQuery.GetDynamicQuery(typeof(T).Name.ToLowerInvariant().Pluralize(), expression);
         return(orm.Select <T>(new SqlCommand(result.Statement, result.Parameters, timeout)).ToList());
     }
 }
Exemplo n.º 6
0
        public async Task <bool> ExecuteAsync <T>(string sql, IList <Parameter> parameters = null, int timeout = 15) where T : class, new()
        {
            var result = false;

            using (IOrm orm = this.orm)
            {
                result = await orm.ExecuteAsync(new SqlCommand(sql, parameters, timeout));
            }
            return(result);
        }
Exemplo n.º 7
0
        public async Task <bool> ExecuteAsync(IList <SqlCommand> unitOfWorks)
        {
            var result = false;

            using (IOrm orm = this.orm)
            {
                result = await orm.ExecuteAsync(unitOfWorks);
            }
            return(result);
        }
Exemplo n.º 8
0
 public bool Insert <T>(T entity, int timeout) where T : class, new()
 {
     if (entity != null)
     {
         SqlCommand queryResult = DynamicQuery.GetInsertQuery(typeof(T).Name.ToLowerInvariant().Pluralize(), entity);
         using (IOrm orm = this.orm)
         {
             return(orm.Execute(new SqlCommand(queryResult.Statement, queryResult.Parameters, timeout)));
         }
     }
     return(false);
 }
Exemplo n.º 9
0
        public async Task <bool> InsertAsync <T>(T entity, int timeout = 15) where T : class, new()
        {
            var result = false;

            if (entity != null)
            {
                SqlCommand queryResult = DynamicQuery.GetInsertQuery(typeof(T).Name.ToLowerInvariant().Pluralize(), entity);
                using (IOrm orm = this.orm)
                {
                    result = await orm.ExecuteAsync(new SqlCommand(queryResult.Statement, queryResult.Parameters, timeout));
                }
            }
            return(result);
        }
Exemplo n.º 10
0
        public async Task <IList <T> > SelectAsync <T>(string sql, IList <Parameter> parameters = null, int timeout = 15) where T : class, new()
        {
            IEnumerable <T> result = null;

            using (IOrm orm = this.orm)
            {
                result = await orm.SelectAsync <T>(new SqlCommand(sql, parameters, timeout), CustomMapper.Resolve <T>());
            }

            if (result == null)
            {
                return(null);
            }

            return(result.ToList());
        }
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            string      connectionstring = "Data Source=.\\SQLEXPRESS;uid=sa;pwd=root;Initial Catalog=test;Integrated Security=SSPI;Integrated Security=True";
            IOrm        orm  = OrmFactory.GetOrm(ServerType.SqlServer, connectionstring);
            IOrm <User> torm = OrmFactory.GetOrm <User>(ServerType.SqlServer, connectionstring);
            string      sql  = "SELECT top 1000 dc.collection_id,dc.collection_name FROM data_collection dc ";
            //string mysql = "SELECT dc.collection_id,dc.collection_name FROM data_collection dc LIMIT 0,1000";
            /*===========================================================================================*/
            Stopwatch s = new Stopwatch();

            s.Start();
            //DataSet ds= MySqlHelper.ExecuteDataset(con, sql);
            //s.Stop();
            //Console.WriteLine(ds.Tables[0].Rows.Count+"条,MySqlHelper DataSet:" + s.ElapsedMilliseconds);
            /*===========================================================================================*/
            s.Restart();
            DataTable t = orm.SqlQuery(sql).ExcuteDataTable();

            s.Stop();
            Console.WriteLine(t.Rows.Count + "条,返回DataTable:" + s.ElapsedMilliseconds);
            /*===========================================================================================*/
            s.Restart();
            List <collection> list = orm.SqlQuery(sql).ToEntityList <collection>();

            s.Stop();
            Console.WriteLine(list.Count + "条,返回List:" + s.ElapsedMilliseconds);
            s.Restart();
            /*===========================================================================================*/
            List <collection> list2 = orm.SqlQuery(sql).ToEntityList <collection>();

            s.Stop();
            Console.WriteLine(list2.Count + "条,第二次List:" + s.ElapsedMilliseconds);
            /*===========================================================================================*/

            //*更新*/
            int count = torm.UpdateColumn("NickName", "TsOrm").Where("Uid=89480").Update();
            //*更新*/
            int count2 = torm.UpdateColumn("NickName", "TsOrm2").Where(x => x.Uid == 89480).Update();
            //*更新*/
            int count3 = torm.UpdateColumn(x => x.NickName, "TsOrm").Where(x => x.Uid == 89480).Update();
            int ccc    = count;
            int ccc2   = count2;
            int ccc3   = count3;

            Console.ReadKey();
        }
Exemplo n.º 12
0
        public async Task <IList <T> > SelectAsync <T>(Expression <Func <T, bool> > expression, int timeout = 15) where T : class, new()
        {
            IEnumerable <T> result = null;

            using (IOrm orm = this.orm)
            {
                SqlCommand query = DynamicQuery.GetDynamicQuery(typeof(T).Name.ToLowerInvariant().Pluralize(), expression);
                result = await orm.SelectAsync <T>(new SqlCommand(query.Statement, query.Parameters, timeout));
            }

            if (result == null)
            {
                return(null);
            }

            return(result.ToList());
        }
Exemplo n.º 13
0
    public static void Main(string[] args)
    {
        IOrm orm = null;

        IDynamodbClient dynamodbClient = null;

        IProductRepository productRepo = new ProductDatabaseRepository(orm);

        ICustomerRepository customerRepo = new CustomerDatabaseRepository(orm);

        Product p1 = productRepo.GetById(3);

        Customer c1 = customerRepo.GetById(49);

        productRepo = new ProductDynamodbRepository(dynamodbClient);

        customerRepo = new CustomerDynamodbRepository(dynamodbClient);

        p1 = productRepo.GetById(3);

        c1 = customerRepo.GetById(49);

        Console.WriteLine("Hello World");
    }
Exemplo n.º 14
0
 /// <summary>
 /// 缓存实例,同步信息实例,编译器实例,ORM信息实例
 /// </summary>
 /// <param name="orm"></param>
 public Transaction(IOrm orm)
 {
     Orm = orm;
 }
 public DatabaseRepositoryBase(IOrm orm, string tableName, string primaryKey)
 {
     _orm        = orm;
     _tableName  = tableName;
     _primaryKey = primaryKey;
 }
Exemplo n.º 16
0
 public ProductDatabaseRepository(IOrm orm) : base(orm, "product", "id")
 {
 }
Exemplo n.º 17
0
 public CustomerDatabaseRepository(IOrm orm) : base(orm, "customer", "id")
 {
 }
Exemplo n.º 18
0
 /// <summary>
 /// Orm实例
 /// </summary>
 /// <param name="orm"></param>
 /// <param name="executor"></param>
 public Key(IOrm orm, IExecutor executor)
 {
     Orm      = orm;
     Executor = executor;
 }