Example #1
0
        public static void InsertTestData <T>(T entity) where T : class
        {
            var temp = Convert.ToInt32(DapperExtension.Instance(DataBaseType.MySql).Insert(GetConnByKey(), entity, null, null));


            return;
        }
Example #2
0
        public void LambaTest()
        {
            #region 查询
            var obj =
                DapperExtension.Instance(DataBaseType.MySql)
                .LambdaQuery <TSoHeader>(Common.GetConnByKey(), null, null);
            var from = obj.Where(p => p.id == 1).Top(1).ToList();
            #endregion

            #region 插入

            //var tHeaderobj = new TSoHeader()
            //{
            //    id = 1000,
            //    cancel = 1,
            //    codec = "order000001",
            //    do_qty = 10,
            //    handle = 1,
            //    invoice_type = 1,
            //    item_need_qty = 20
            //};
            //var insetobj = DapperExtension.Instance().LambdaInsert<TSoHeader>(Common.GetConnByKey(),null,null);
            #endregion

            #region 更新

            var updateobj = DapperExtension.Instance().LambdaUpdate <TSoHeader>(Common.GetConnByKey(), null, null);
            #endregion
        }
Example #3
0
        /// <summary>
        /// 初始化数据库
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static LambdaQueryHelper <T> Create <T>() where T : class
        {
            Type type = typeof(T);

            TableMapping       map   = type.GetCustomAttributes(typeof(TableMapping), false)[0] as TableMapping;
            TableConfiguration table = config.Where(p => p.Name == map.ConfigName).FirstOrDefault();

            DataBaseType  BaseType;
            IDbConnection connection;

            if (table != null)
            {
                switch (table.SqlType)
                {
                case "MsSql": BaseType = DataBaseType.SqlServer; connection = GetMsSqlConn(table.ConnectString); break;

                case "MySql": BaseType = DataBaseType.MySql; connection = GetMySqlConn(table.ConnectString); break;

                default: BaseType = DataBaseType.SqlServer; connection = GetMsSqlConn(table.ConnectString); break;
                }
                return(DapperExtension.Instance(BaseType).LambdaQuery <T>(connection, null, null));
            }
            else
            {
                return(null);
            }
        }