Exemple #1
0
        /// <summary>
        /// 解释Condition条件
        /// </summary>
        /// <param name="scope">条件</param>
        /// <param name="list"></param>
        /// <param name="entityType"></param>
        /// <param name="paramName"></param>
        /// <param name="type"></param>
        /// <param name="lstIndex"></param>
        public static string Condition(Scope scope, ParamList list, Type entityType, string paramName, DbType type, int lstIndex)
        {
            DBInfo        db            = EntityInfoManager.GetEntityHandle(entityType).DBInfo;
            string        paramVal      = db.CurrentDbAdapter.FormatValueName(DataAccessCommon.FormatParam(paramName, lstIndex));
            string        paramKey      = db.CurrentDbAdapter.FormatParamKeyName(DataAccessCommon.FormatParam(paramName, lstIndex));
            StringBuilder sql           = new StringBuilder(500);
            ScopeType     ctype         = scope.ScopeType;
            string        connectString = DataAccessCommon.GetConnectString(scope);

            BQLCondition fhandle = scope.Value1 as BQLCondition;

            if (!CommonMethods.IsNull(fhandle))
            {
                KeyWordInfomation info = new KeyWordInfomation();
                info.Infos  = new Buffalo.DB.BQLCommon.BQLInfos();
                info.DBInfo = db;

                info.ParamList = list;
                sql.Append(" ");
                sql.Append(connectString);

                sql.Append(" (" + fhandle.DisplayValue(info) + ")");
            }
            return(sql.ToString());
        }
Exemple #2
0
 /// <summary>
 /// 初始化本类的信息
 /// </summary>
 /// <param name="entityInfo">类信息</param>
 public MyClass_ManBase(BQLEntityTableHandle parent, string propertyName)
     : base(EntityInfoManager.GetEntityHandle(typeof(TestAddIn.ManBase)), parent, propertyName)
 {
     _id         = CreateProperty("Id");
     _state      = CreateProperty("State");
     _lastUpdate = CreateProperty("LastUpdate");
 }
Exemple #3
0
        /// <summary>
        /// 填充该列表的子类
        /// </summary>
        /// <param name="sender">发送者</param>
        public static void FillParent(string propertyName, EntityBase sender)
        {
            if (sender.HasPropertyChange(propertyName))
            {
                return;
            }
            Type              senderType  = CH.GetRealType(sender);                        //发送者类型
            EntityInfoHandle  senderInfo  = EntityInfoManager.GetEntityHandle(senderType); //获取发送类的信息
            EntityMappingInfo mappingInfo = senderInfo.MappingInfo[propertyName];

            //if (mappingInfo.GetValue(sender) != null)
            //{
            //    return;
            //}
            //IList baseList = sender.GetBaseList();//获取上一次查询的结果集合
            //if (baseList == null)
            //{
            //    baseList = new ArrayList();
            //    baseList.Add(sender);
            //}
            //Dictionary<string, ArrayList> dicElement = new Dictionary<string, ArrayList>();

            if (mappingInfo != null)
            {
                EntityPropertyInfo senderHandle = mappingInfo.SourceProperty;//本类的主键属性句柄

                //IList pks = CollectFks(baseList, senderHandle, mappingInfo, dicElement, senderInfo.DBInfo);
                EntityInfoHandle fatherInfo = mappingInfo.TargetProperty.BelongInfo;
                object           pk         = senderHandle.GetValue(sender);
                FillParent(pk, fatherInfo, mappingInfo, propertyName, sender);
            }
        }
Exemple #4
0
        /// <summary>
        /// 建方法
        /// </summary>
        /// <param name="classType"></param>
        /// <param name="inspectorFieldBuilder"></param>
        /// <param name="typeBuilder"></param>
        private void BuildMethod(Type classType, TypeBuilder typeBuilder)
        {
            EntityInfoHandle entityInfo = EntityInfoManager.GetEntityHandle(classType);
            MethodInfo       method     = null;

            foreach (EntityPropertyInfo pInfo in entityInfo.PropertyInfo)
            {
                UpdatePropertyInfo updateInfo = entityInfo.GetUpdatePropertyInfo(pInfo.PropertyName);
                if (updateInfo != null)
                {
                    method = _mapupdateMethod;//如果是关联属性则调用OnMapPropertyUpdated
                }
                else
                {
                    method = _updateMethod;//如果是一般属性则调用OnPropertyUpdated通知
                }
                BuildEmit(classType, pInfo.BelongPropertyInfo, typeBuilder, method);
            }


            foreach (EntityMappingInfo mInfo in entityInfo.MappingInfo)
            {
                FieldInfo finfo = mInfo.BelongFieldInfo;
                if (mInfo.IsParent)
                {
                    BuildEmit(classType, mInfo.BelongPropertyInfo, typeBuilder, _mapupdateMethod);      //创建set方法
                    BuildMapEmit(classType, mInfo.BelongPropertyInfo, finfo, typeBuilder, _fillParent); //创建get方法
                }
                else
                {
                    BuildMapEmit(classType, mInfo.BelongPropertyInfo, finfo, typeBuilder, _fillChildMethod);//创建get方法
                }
            }
        }
        /// <summary>
        /// 填充子属性列表
        /// </summary>
        /// <param name="lst">集合</param>
        /// <param name="childPropertyName">子属性名</param>
        /// <param name="objs">实体</param>
        /// <param name="objType">类型</param>
        /// <param name="filter">筛选条件</param>
        private static void FillEntityChidList(IEnumerable lst, string childPropertyName, Queue <object> objs, Type objType, ScopeList filter)
        {
            if (lst == null)
            {
                return;
            }

            EntityInfoHandle entityInfo = EntityInfoManager.GetEntityHandle(objType);

            if (entityInfo == null)
            {
                throw new Exception("找不到类:" + objType.FullName + "的映射");
            }
            EntityMappingInfo mappingInfo = entityInfo.MappingInfo[childPropertyName];

            if (mappingInfo == null)
            {
                throw new Exception("找不到子属性:" + childPropertyName);
            }
            Queue <object>   pks                    = CollectFks(lst, mappingInfo.SourceProperty);
            EntityInfoHandle childHandle            = mappingInfo.TargetProperty.BelongInfo;//获取子元素的信息
            Dictionary <string, List <object> > dic = GetEntityDictionary(lst, mappingInfo);

            FillChilds(pks, childHandle, mappingInfo, dic, childPropertyName, objs, filter);
        }
Exemple #6
0
        /// <summary>
        /// 解释EndWith条件
        /// </summary>
        /// <param name="list"></param>
        /// <param name="entityType"></param>
        /// <param name="paramName"></param>
        /// <param name="type"></param>
        /// <param name="lstIndex"></param>
        public static string EndWith(Scope scope, ParamList list, Type entityType, string paramName, DbType type, int lstIndex)
        {
            DBInfo        db            = EntityInfoManager.GetEntityHandle(entityType).DBInfo;
            string        paramVal      = db.CurrentDbAdapter.FormatValueName(DataAccessCommon.FormatParam(paramName, lstIndex));
            string        paramKey      = db.CurrentDbAdapter.FormatParamKeyName(DataAccessCommon.FormatParam(paramName, lstIndex));
            StringBuilder sql           = new StringBuilder(500);
            ScopeType     ctype         = scope.ScopeType;
            string        connectString = DataAccessCommon.GetConnectString(scope);

            if (list != null)
            {
                sql.Append(" ");
                sql.Append(connectString);
                sql.Append(" (" + db.CurrentDbAdapter.FormatParam(paramName) + " like " + db.CurrentDbAdapter.ConcatString("'%'", paramVal) + ")");
                list.AddNew(paramKey, type, scope.Value1);
            }
            else
            {
                sql.Append(" ");
                sql.Append(connectString);
                string curValue = scope.Value1.ToString();
                sql.Append(" (" + db.CurrentDbAdapter.FormatParam(paramName) + " like '%" + scope.Value1 + "')");
            }
            return(sql.ToString());
        }
Exemple #7
0
        /// <summary>
        /// 解释MoreThen条件
        /// </summary>
        /// <param name="list"></param>
        /// <param name="entityType"></param>
        /// <param name="paramName"></param>
        /// <param name="type"></param>
        /// <param name="lstIndex"></param>
        public static string MoreThen(Scope scope, ParamList list, Type entityType, string paramName, DbType type, int lstIndex)
        {
            DBInfo        db            = EntityInfoManager.GetEntityHandle(entityType).DBInfo;
            string        paramVal      = db.CurrentDbAdapter.FormatValueName(DataAccessCommon.FormatParam(paramName, lstIndex));
            string        paramKey      = db.CurrentDbAdapter.FormatParamKeyName(DataAccessCommon.FormatParam(paramName, lstIndex));
            StringBuilder sql           = new StringBuilder(500);
            ScopeType     ctype         = scope.ScopeType;
            string        connectString = DataAccessCommon.GetConnectString(scope);

            if (list != null)
            {
                sql.Append(" ");
                sql.Append(connectString);
                sql.Append(" (");
                sql.Append(db.CurrentDbAdapter.FormatParam(paramName));
                sql.Append(" >= ");
                sql.Append(paramVal);
                sql.Append(")");
                list.AddNew(paramKey, type, scope.Value1);
            }
            else
            {
                sql.Append(" ");
                sql.Append(connectString);
                sql.Append(" (");
                sql.Append(db.CurrentDbAdapter.FormatParam(paramName));
                sql.Append(" >= ");
                sql.Append(DataAccessCommon.FormatValue(scope.Value1, type, db));
                sql.Append(")");
            }
            return(sql.ToString());
        }
Exemple #8
0
        /// <summary>
        /// 解释NotIN条件(如果集合为空,则返回1=1)
        /// </summary>
        /// <param name="list"></param>
        /// <param name="entityType"></param>
        /// <param name="paramName"></param>
        /// <param name="type"></param>
        /// <param name="lstIndex"></param>
        public static string NotIN(Scope scope, ParamList list, Type entityType, string paramName, DbType type, int lstIndex)
        {
            DBInfo        db            = EntityInfoManager.GetEntityHandle(entityType).DBInfo;
            string        paramVal      = db.CurrentDbAdapter.FormatValueName(DataAccessCommon.FormatParam(paramName, lstIndex));
            string        paramKey      = db.CurrentDbAdapter.FormatParamKeyName(DataAccessCommon.FormatParam(paramName, lstIndex));
            StringBuilder sql           = new StringBuilder(500);
            ScopeType     ctype         = scope.ScopeType;
            string        connectString = DataAccessCommon.GetConnectString(scope);
            string        inValue       = null;

            inValue = GetInString(scope.Value1, type, db);
            if (inValue != "" && inValue != null)
            {
                sql.Append(" ");
                sql.Append(connectString);
                sql.Append(" (");
                sql.Append(db.CurrentDbAdapter.FormatParam(paramName));
                sql.Append(" not in (");
                sql.Append(inValue);
                sql.Append("))");
            }
            else //没有数据时候设置改条件不成立
            {
                sql.Append(" ");
                sql.Append(connectString);
                sql.Append(" 1=1");
            }
            return(sql.ToString());
        }
Exemple #9
0
 /// <summary>
 /// 初始化本类的信息
 /// </summary>
 /// <param name="entityInfo">类信息</param>
 public MyClass_ManMessage(BQLEntityTableHandle parent, string propertyName)
     : base(EntityInfoManager.GetEntityHandle(typeof(TestAddIn.ManMessage)), parent, propertyName)
 {
     _title      = CreateProperty("Title");
     _content    = CreateProperty("Content");
     _belongUser = CreateProperty("BelongUser");
 }
Exemple #10
0
 /// <summary>
 /// 获取当前实体的信息
 /// </summary>
 /// <returns></returns>
 public EntityInfoHandle GetEntityInfo()
 {
     if (_thisInfo == null)
     {
         _thisInfo = EntityInfoManager.GetEntityHandle(CH.GetRealType(this));
     }
     return(_thisInfo);
 }
Exemple #11
0
 /// <summary>
 /// 初始化本类的信息
 /// </summary>
 /// <param name="entityInfo">类信息</param>
 public MyClass_ManEmployee(BQLEntityTableHandle parent, string propertyName)
     : base(EntityInfoManager.GetEntityHandle(typeof(TestAddIn.ManEmployee)), parent, propertyName)
 {
     _name    = CreateProperty("Name");
     _pwd     = CreateProperty("Pwd");
     _classId = CreateProperty("ClassId");
     _remark  = CreateProperty("Remark");
     _IDCard  = CreateProperty("IDCard");
 }
Exemple #12
0
 /// <summary>
 /// 获取基础数据层
 /// </summary>
 /// <returns></returns>
 private DataAccessSetBase GetBaseDataAccess()
 {
     if (_dal == null)
     {
         EntityInfoHandle handle = EntityInfoManager.GetEntityHandle(CH.GetRealType(this));
         _dal      = new DataAccessSetBase(handle);
         _dal.Oper = StaticConnection.GetStaticOperate(handle.DBInfo);
     }
     return(_dal);
 }
Exemple #13
0
 /// <summary>
 /// 获取数据层(用作运行SQL)
 /// </summary>
 /// <returns></returns>
 public DataAccessSetBase GetDAL()
 {
     if (_dal == null)
     {
         EntityInfoHandle handle = EntityInfoManager.GetEntityHandle(typeof(T));
         _dal      = new DataAccessSetBase(handle);
         _dal.Oper = StaticConnection.GetStaticOperate(handle.DBInfo);
     }
     return(_dal);
 }
        /// <summary>
        /// 获取类型对应的表名
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public string GetTableName(Type type)
        {
            EntityInfoHandle eInfo = EntityInfoManager.GetEntityHandle(type);

            if (eInfo != null)
            {
                return(eInfo.TableName);
            }
            return("");
        }
Exemple #15
0
        /// <summary>
        /// 获取排序
        /// </summary>
        /// <param name="lstScort"></param>
        /// <param name="table"></param>
        /// <param name="entityType"></param>
        /// <returns></returns>
        protected BQLParamHandle[] GetSort(SortList lstScort, BQLTableHandle table, Type entityType)
        {
            EntityInfoHandle entityInfo = null;

            if (entityType != null)
            {
                entityInfo = EntityInfoManager.GetEntityHandle(entityType);
            }
            return(BQLConditionScope.GetSort(lstScort, table, entityInfo));
        }
Exemple #16
0
 /// <summary>
 /// 初始化本类的信息
 /// </summary>
 /// <param name="entityInfo">类信息</param>
 public MyClass_ManUsers(BQLEntityTableHandle parent, string propertyName)
     : base(EntityInfoManager.GetEntityHandle(typeof(TestAddIn.ManUsers)), parent, propertyName)
 {
     _name     = CreateProperty("Name");
     _remark   = CreateProperty("Remark");
     _userType = CreateProperty("UserType");
     _classId  = CreateProperty("ClassId");
     _image    = CreateProperty("Image");
     _age      = CreateProperty("Age");
     _password = CreateProperty("Password");
 }
Exemple #17
0
        /// <summary>
        /// 填充信息
        /// </summary>
        /// <param name="condition"></param>
        /// <param name="table"></param>
        /// <param name="lstScope"></param>
        /// <param name="entityType"></param>
        public BQLCondition FillCondition(BQLCondition condition, BQLTableHandle table, ScopeList lstScope, Type entityType)
        {
            BQLCondition     ret;
            EntityInfoHandle entityInfo = null;

            if (entityType != null)
            {
                entityInfo = EntityInfoManager.GetEntityHandle(entityType);
            }
            ret = BQLConditionScope.FillCondition(condition, table, lstScope, entityInfo);
            return(ret);
        }
Exemple #18
0
        /// <summary>
        /// 解释Contains条件
        /// </summary>
        /// <param name="list"></param>
        /// <param name="entityType"></param>
        /// <param name="paramName"></param>
        /// <param name="type"></param>
        /// <param name="lstIndex"></param>
        public static string Contains(Scope scope, ParamList list, Type entityType, string paramName, DbType type, int lstIndex)
        {
            DBInfo        db            = EntityInfoManager.GetEntityHandle(entityType).DBInfo;
            string        paramVal      = db.CurrentDbAdapter.FormatValueName(DataAccessCommon.FormatParam(paramName, lstIndex));
            string        paramKey      = db.CurrentDbAdapter.FormatParamKeyName(DataAccessCommon.FormatParam(paramName, lstIndex));
            StringBuilder sql           = new StringBuilder(500);
            ScopeType     ctype         = scope.ScopeType;
            string        connectString = DataAccessCommon.GetConnectString(scope);

            sql.Append(FullTextConfigManager.GetLikeSql(scope, list, paramName, type, lstIndex, entityType, connectString, true));
            return(sql.ToString());
        }
Exemple #19
0
        /// <summary>
        /// 获取指定对应字段名的属性句柄
        /// </summary>
        /// <param name="type">类型</param>
        /// <param name="pkName">字段名</param>
        /// <returns></returns>
        private static EntityPropertyInfo GetPkHandle(Type type, string pkName)
        {
            EntityInfoHandle classInfo = EntityInfoManager.GetEntityHandle(type);

            foreach (EntityPropertyInfo info in classInfo.PropertyInfo)
            {
                if (pkName == info.ParamName)
                {
                    return(info);
                }
            }
            return(null);
        }
Exemple #20
0
        /// <summary>
        /// 从Reader里边读取一个对象数据
        /// </summary>
        /// <typeparam name="T">类型</typeparam>
        /// <param name="reader">reader</param>
        /// <returns></returns>
        public static T LoadFormReader <T>(IDataReader reader) where T : EntityBase, new()
        {
            EntityInfoHandle entityInfo = EntityInfoManager.GetEntityHandle(typeof(T));

            if (reader != null && !reader.IsClosed)
            {
                List <EntityPropertyInfo> lstParamNames = GenerateCache(reader, entityInfo);
                T ret = (T)entityInfo.CreateSelectProxyInstance();//实例化对象
                FillObjectFromReader(reader, lstParamNames, ret, entityInfo.DBInfo);
                return(ret);
            }
            return(default(T));
        }
Exemple #21
0
        /// <summary>
        /// 填充该列表的子类
        /// </summary>
        /// <param name="sender">发送者</param>
        public static void FillChildList(string propertyName, EntityBase sender)
        {
            Type              senderType   = CH.GetRealType(sender);                        //发送类的类型
            EntityInfoHandle  senderHandle = EntityInfoManager.GetEntityHandle(senderType); //获取发送类的信息
            EntityMappingInfo mappingInfo  = senderHandle.MappingInfo[propertyName];

            if (mappingInfo != null)
            {
                EntityPropertyInfo pkHandle = mappingInfo.SourceProperty;//获取实体主键属性句柄
                object             lst      = Activator.CreateInstance(mappingInfo.FieldType);
                mappingInfo.SetValue(sender, lst);
                object           pk          = pkHandle.GetValue(sender);
                EntityInfoHandle childHandle = mappingInfo.TargetProperty.BelongInfo;//获取子元素的信息
                FillChilds(pk, childHandle, mappingInfo, sender, propertyName);
            }
        }
Exemple #22
0
        /// <summary>
        /// 转成条件信息
        /// </summary>
        /// <param name="BQL"></param>
        /// <param name="db"></param>
        /// <param name="aliasManager"></param>
        /// <returns></returns>
        private AbsCondition ToCondition(BQLQuery BQL, IEnumerable <BQLEntityTableHandle> outPutTables,
                                         bool isPutPropertyName, Type entityType)
        {
            TableAliasNameManager aliasManager = null;

            if (entityType != null)
            {
                aliasManager = new TableAliasNameManager(new BQLEntityTableHandle(EntityInfoManager.GetEntityHandle(entityType)));
            }
            if (outPutTables != null)
            {
                FillOutPutTables(outPutTables, aliasManager);
            }
            AbsCondition con = BQLKeyWordManager.ToCondition(BQL, _oper.DBInfo, aliasManager, isPutPropertyName);

            return(con);
        }
Exemple #23
0
        /// <summary>
        /// 从Reader里边读取数据集合(快速)
        /// </summary>
        /// <typeparam name="T">类型</typeparam>
        /// <param name="reader">reader</param>
        /// <returns></returns>
        public static List <T> LoadFormReaderList <T>(IDataReader reader) where T : EntityBase, new()
        {
            EntityInfoHandle entityInfo = EntityInfoManager.GetEntityHandle(typeof(T));
            List <T>         retLst     = new List <T>();

            if (reader != null && !reader.IsClosed)
            {
                List <EntityPropertyInfo> lstParamNames = GenerateCache(reader, entityInfo);

                while (reader.Read())
                {
                    T obj = entityInfo.CreateSelectProxyInstance() as T;
                    FillObjectFromReader(reader, lstParamNames, obj, entityInfo.DBInfo);
                    retLst.Add(obj);
                }
            }
            return(retLst);
        }
Exemple #24
0
        /// <summary>
        /// 返回Like的查询字符串
        /// </summary>
        /// <param name="scope">条件类</param>
        /// <param name="list">参数列表</param>
        /// <param name="paranName">所属的字段名</param>
        /// <param name="type">当前的数据库类型</param>
        /// <param name="lstIndex">当前索引的标识未辨别同名字段的参数,可设置为0</param>
        /// <param name="entityType">当前实体的类型</param>
        /// <param name="connectString">条件连接的字符串</param>
        /// <param name="isFreeText">是否全文检索</param>
        /// <returns></returns>
        public static string GetLikeSql(Scope scope, ParamList list, string paranName, DbType type, int lstIndex, Type entityType, string connectString, bool isFreeText)
        {
            //string fullName = entityType.FullName + "." + scope.PropertyName;
            DBInfo db       = EntityInfoManager.GetEntityHandle(entityType).DBInfo;
            string ret      = " " + connectString;
            string paramVal = db.CurrentDbAdapter.FormatValueName(DataAccessCommon.FormatParam(paranName, lstIndex));
            string paramKey = db.CurrentDbAdapter.FormatParamKeyName(DataAccessCommon.FormatParam(paranName, lstIndex));

            if (isFreeText && !NoiseWord.IsNoiseWord(scope.Value1.ToString()))
            {
                if (list != null)
                {
                    ret += db.CurrentDbAdapter.FreeTextLike(paranName, paramVal);

                    list.AddNew(paramKey, type, scope.Value1);
                }
                else
                {
                    ret += db.CurrentDbAdapter.FreeTextLike(paranName, DataAccessCommon.FormatValue(scope.Value1, type, db));
                }
            }
            else
            {
                if (list != null)
                {
                    string curValue = scope.Value1.ToString();
                    curValue = FilterLikeValue(curValue);
                    ret     += " (" + db.CurrentDbAdapter.FormatParam(paranName) + " like " + db.CurrentDbAdapter.ConcatString("'%'", paramVal, "'%'") + ")";
                    list.AddNew(paramKey, type, curValue);
                }
                else
                {
                    string curValue = scope.Value1.ToString();
                    curValue = FilterLikeValue(curValue);
                    ret     += " (" + db.CurrentDbAdapter.FormatParam(paranName) + " like '%" + curValue + "%')";
                }
            }
            return(ret);
        }
Exemple #25
0
        /// <summary>
        /// 根据Reader结构和实体属性的映射生成空的DataTable
        /// </summary>
        /// <param name="reader">Reader</param>
        /// <param name="datatableName">数据表名</param>
        /// <param name="entityType">实体类</param>
        /// <param name="isEmpty">是否生成空的DataTable</param>
        /// <returns></returns>
        public static DataTable GenerateDataTable(IDataReader reader, string datatableName, Type entityType, bool isEmpty)
        {
            DataTable                 dt            = new DataTable();
            EntityInfoHandle          entityInfo    = EntityInfoManager.GetEntityHandle(entityType);
            List <EntityPropertyInfo> lstParamNames = GenerateCache(reader, entityInfo);

            dt.BeginLoadData();
            foreach (EntityPropertyInfo info in lstParamNames)
            {
                if (info != null)
                {
                    Type fieldType = info.FieldType;
                    if (DefaultType.EqualType(fieldType, DefaultType.BooleanType))
                    {
                        fieldType = typeof(bool);
                    }
                    dt.Columns.Add(info.PropertyName, fieldType);
                }
            }
            if (!isEmpty)
            {
                while (reader.Read())
                {
                    DataRow dr = dt.NewRow();
                    for (int i = 0; i < lstParamNames.Count; i++)
                    {
                        if (!reader.IsDBNull(i) && lstParamNames[i] != null)
                        {
                            dr[i] = reader[i];
                        }
                    }
                    dt.Rows.Add(dr);
                    dt.AcceptChanges();
                }
            }
            dt.EndLoadData();
            return(dt);
        }
Exemple #26
0
        /// <summary>
        /// 从DataReader加载
        /// </summary>
        /// <param name="reader"></param>
        public void LoadFromReader(IDataReader reader)
        {
            EntityInfoHandle entityInfo = EntityInfoManager.GetEntityHandle(CH.GetRealType(this));

            CacheReader.FillInfoFromReader(reader, entityInfo, this);
        }
 public BQLEntityTableHandle(Type entityType, BQLEntityTableHandle parentTable, string propertyName)
 {
     SetEntityInfo(EntityInfoManager.GetEntityHandle(entityType), parentTable, propertyName);
 }
Exemple #28
0
        /// <summary>
        /// 获取第一条记录
        /// </summary>
        /// <typeparam name="E"></typeparam>
        /// <param name="BQL"></param>
        /// <returns></returns>
        public E GetUnique <E>(BQLQuery BQL, bool useCache)
            where E : EntityBase, new()
        {
            Type tableType = typeof(E);
            TableAliasNameManager aliasManager = new TableAliasNameManager(new BQLEntityTableHandle(EntityInfoManager.GetEntityHandle(tableType)));


            AbsCondition con = BQLKeyWordManager.ToCondition(BQL, _oper.DBInfo, aliasManager, true);
            Dictionary <string, bool> cacheTables = null;

            if (useCache)
            {
                cacheTables = con.CacheTables;
            }
            string      sql    = con.DBinfo.CurrentDbAdapter.GetTopSelectSql(con as SelectCondition, 1);
            E           ret    = default(E);
            IDataReader reader = _oper.Query(sql, con.DbParamList, cacheTables);

            try
            {
                con.Oper = _oper;
                bool hasValue = true;
                aliasManager.InitMapping(reader);
                if (reader.Read())
                {
                    ret = aliasManager.LoadFromReader(reader) as E;
                }
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
            return(ret);
        }
Exemple #29
0
        /// <summary>
        /// 查询总条数
        /// </summary>
        /// <param name="lstScope"></param>
        /// <returns></returns>
        public virtual long SelectCount <E>(ScopeList lstScope)
        {
            long ret   = 0;
            Type eType = typeof(E);
            TableAliasNameManager aliasManager = new TableAliasNameManager(new BQLEntityTableHandle(EntityInfoManager.GetEntityHandle(typeof(E))));
            BQLEntityTableHandle  table        = _oper.DBInfo.FindTable(eType);

            if (CommonMethods.IsNull(table))
            {
                _oper.DBInfo.ThrowNotFondTable(eType);
            }

            BQLCondition where = BQLCondition.TrueValue;
            where = FillCondition(where, table, lstScope);
            BQLQuery bql = BQL.Select(BQL.Count())
                           .From(table)
                           .Where(where);

            //if(lstScope.GroupBy

            AbsCondition con = BQLKeyWordManager.ToCondition(bql, _oper.DBInfo, aliasManager, true);
            Dictionary <string, bool> cacheTables = null;

            if (lstScope.UseCache)
            {
                cacheTables = con.CacheTables;
            }
            using (IDataReader reader = _oper.Query(con.GetSql(lstScope.UseCache), con.DbParamList, cacheTables))
            {
                if (reader.Read())
                {
                    ret = Convert.ToInt64(reader[0]);
                }
            }
            return(ret);
        }
Exemple #30
0
 /// <summary>
 /// 数据层基类
 /// </summary>
 /// <param name="entityType">关联实体</param>
 public BQLDbBase(Type entityType)
     : this(EntityInfoManager.GetEntityHandle(entityType).DBInfo)
 {
 }