예제 #1
0
파일: Repository.cs 프로젝트: bzure/BCF
        protected Entity[] ProcessEntityQueryRequestNonePaged <Entity>(EntityQueryRequest <Entity> QueryRequest) where Entity : IEntity
        {
            Dictionary <string, MemberDataMap> MapSet = new Dictionary <string, MemberDataMap>();

            lock (DataMapContainer)
            {
                Dictionary <string, MemberDataMap> MapSetTemp;
                if (DataMapContainer.TryGetValue(typeof(Entity), out MapSetTemp))
                {
                    foreach (KeyValuePair <string, MemberDataMap> kvp in MapSetTemp)
                    {
                        MapSet[kvp.Key] = kvp.Value.Copy();
                    }
                }
                else
                {
                    throw new Exception(string.Format("类型:{0}没有在构建静态构造中初始化实体{1}的数据更新映射", this.GetType().Name, typeof(Entity).Name));
                }
            }
            Delegate queryMap = null;

            if (!QueryMapContainer.TryGetValue(typeof(Entity), out queryMap))
            {
                throw new Exception(string.Format("类型:{0}没有在构建静态构造中初始化实体{1}的数据查询映射", this.GetType().Name, typeof(Entity).Name));
            }
            ResultMapDelegate <Entity> qMap = queryMap as ResultMapDelegate <Entity>;
            //查寻的条件
            List <IDataMemberMap> ConditionDataMemberMapList = new List <IDataMemberMap>();

            foreach (IEntityMemberMap map in QueryRequest.ConditionMap)
            {
                if (map is EntityMemberMap)
                {
                    EntityMemberMap EntityMemberMap = map as EntityMemberMap;
                    MemberDataMap   MemberDataMap;
                    if (MapSet.TryGetValue(EntityMemberMap.MemberName, out MemberDataMap))
                    {
                        ConditionDataMemberMapList.AppendMember(MemberDataMap, EntityMemberMap);
                    }
                }
                else if (map is LogicLinkMap)
                {
                    ConditionDataMemberMapList.Add(map as LogicLinkMap);
                }
            }
            EntityMap <Entity> QueryHandler = this.CreateEntityMap <Entity>(BuildQuerySql(this.TableName, ConditionDataMemberMapList));

            //添加条件参数
            foreach (DataMemberMap DataMemberMap in ConditionDataMemberMapList.Where(m => (m is DataMemberMap)))
            {
                QueryHandler.AddParameter(DataMemberMap);
            }
            return(QueryHandler.SetMap(qMap).AsList().ToArray());
        }
예제 #2
0
        static UserRoleMapRepository()
        {
            UserRoleMap entity = new UserRoleMap();
            Type        type   = entity.GetType();

            AppendDataMap(type, "UserID", () => entity.UserID);
            AppendDataMap(type, "RoleID", () => entity.RoleID);
            ResultMapDelegate <UserRoleMap> queryMap = UsersInRoles_Map;

            QueryMapContainer[entity.GetType()] = queryMap;
        }
예제 #3
0
        static RoleRepository()
        {
            TeamRole entity = new TeamRole(Guid.NewGuid().ToString(), string.Empty);
            Type     type   = entity.GetType();

            AppendDataMap(type, "RoleID", () => entity.ID);
            AppendDataMap(type, "RoleName", () => entity.Name);
            AppendDataMap(type, "Description", () => entity.RoleDescription);
            ResultMapDelegate <TeamRole> queryMap = Role_Map;

            QueryMapContainer[entity.GetType()] = queryMap;
        }
예제 #4
0
        static UserBindRepository()
        {
            UserBind entity = new UserBind();
            Type     type   = entity.GetType();

            AppendDataMap(type, "ID", () => entity.ID);
            AppendDataMap(type, "UserID", () => entity.UserID);
            AppendDataMap(type, "BindID", () => entity.BindID);
            AppendDataMap(type, "BindProvider", () => entity.BindProvider);
            ResultMapDelegate <UserBind> queryMap = UserBind_Map;

            QueryMapContainer[entity.GetType()] = queryMap;
        }
예제 #5
0
        static PasswordTokenRepository()
        {
            PasswordToken entity = new PasswordToken();
            Type          type   = entity.GetType();

            AppendDataMap(type, "CreateTime", () => entity.CreateTime);
            AppendDataMap(type, "Expire", () => entity.Expire);
            AppendDataMap(type, "Token", () => entity.Token);
            AppendDataMap(type, "UserName", () => entity.UserName);
            ResultMapDelegate <PasswordToken> queryMap = PasswordToken_Map;

            QueryMapContainer[entity.GetType()] = queryMap;
        }
예제 #6
0
        static DroitResourceRepository()
        {
            DroitResource entity = new DroitResource(Guid.NewGuid().ToString());
            Type          type   = entity.GetType();

            AppendDataMap(type, "ResourceID", () => entity.ResourceID);
            AppendDataMap(type, "ResourceName", () => entity.ResourceName);
            AppendDataMap(type, "RoleID", () => entity.RoleID);
            AppendDataMap(type, "RightValue", () => entity.RightValue);
            AppendDataMap(type, "State", () => entity.State);
            ResultMapDelegate <DroitResource> queryMap = Resource_Map;

            QueryMapContainer[entity.GetType()] = queryMap;
        }
예제 #7
0
        static UserRepository()
        {
            BzureUser entity = new BzureUser(string.Empty, string.Empty);
            Type      type   = entity.GetType();

            AppendDataMap(type, "UserID", () => entity.UserID);
            AppendDataMap(type, "UserName", () => entity.UserName);
            AppendDataMap(type, "Password", () => entity.Password);
            AppendDataMap(type, "State", () => entity.State);
            AppendDataMap(type, "EMail", () => entity.EMail);
            AppendDataMap(type, "OpenID", () => entity.OpenID);
            AppendDataMap(type, "RoleValue", () => entity.RoleValue);
            AppendDataMap(type, "NickName", () => entity.NickName);
            ResultMapDelegate <BzureUser> queryMap = BzureUser_Map;

            QueryMapContainer[entity.GetType()] = queryMap;
        }
예제 #8
0
 /// <summary>
 /// Takes the function that maps the DataReader to an actual object
 /// </summary>
 /// <param name="resultMapDelegate"></param>
 /// <returns></returns>
 public EntityMap <T> SetMap(ResultMapDelegate <T> resultMapDelegate)
 {
     _mapper = resultMapDelegate;
     return(this);
 }
예제 #9
0
 public IEnumerable <T> AsEnumerable(ResultMapDelegate <T> map)
 {
     _mapper = map;
     return(AsEnumerable());
 }
예제 #10
0
 public List <T> AsList(ResultMapDelegate <T> map)
 {
     _mapper = map;
     return(AsList());
 }
예제 #11
0
        protected override Entity[] ProcessEntityQueryRequestPaged <Entity>(Bzure.Common.Data.EntityPageQueryRequest <Entity> QueryRequest)
        {
            Dictionary <string, MemberDataMap> MapSet = new Dictionary <string, MemberDataMap>();

            lock (DataMapContainer)
            {
                Dictionary <string, MemberDataMap> MapSetTemp;
                if (DataMapContainer.TryGetValue(typeof(Entity), out MapSetTemp))
                {
                    foreach (KeyValuePair <string, MemberDataMap> kvp in MapSetTemp)
                    {
                        MapSet[kvp.Key] = kvp.Value.Copy();
                    }
                }
                else
                {
                    throw new Exception(string.Format("类型:{0}没有在构建静态构造中初始化实体{1}的数据更新映射", this.GetType().Name, typeof(Entity).Name));
                }
            }
            Delegate queryMap = null;

            if (!QueryMapContainer.TryGetValue(typeof(Entity), out queryMap))
            {
                throw new Exception(string.Format("类型:{0}没有在构建静态构造中初始化实体{1}的数据查询映射", this.GetType().Name, typeof(Entity).Name));
            }
            ResultMapDelegate <Entity> qMap = queryMap as ResultMapDelegate <Entity>;
            //查寻的条件
            List <IDataMemberMap> ConditionDataMemberMapList = new List <IDataMemberMap>();

            foreach (IEntityMemberMap map in QueryRequest.ConditionMap)
            {
                if (map is EntityMemberMap)
                {
                    EntityMemberMap EntityMemberMap = map as EntityMemberMap;
                    MemberDataMap   MemberDataMap;
                    if (MapSet.TryGetValue(EntityMemberMap.MemberName, out MemberDataMap))
                    {
                        ConditionDataMemberMapList.Add(new DataMemberMap()
                        {
                            DataFieldName = MemberDataMap.DataFieldName,
                            DataValue     = EntityMemberMap.MemberValue,
                            Operator      = EntityMemberMap.Operator
                        });
                    }
                }
                else if (map is LogicLinkMap)
                {
                    ConditionDataMemberMapList.Add(map as LogicLinkMap);
                }
            }

            //排序字段
            DataMemberMap OrderFiledmap = default(DataMemberMap);

            if (QueryRequest.OrderByMember != default(EntityMemberMap))
            {
                MemberDataMap mdm;
                if (MapSet.TryGetValue(QueryRequest.OrderByMember.MemberName, out mdm))
                {
                    OrderFiledmap = new DataMemberMap()
                    {
                        DataFieldName = mdm.DataFieldName,
                        DataValue     = QueryRequest.OrderByMember.MemberValue,
                        Operator      = QueryRequest.OrderByMember.Operator
                    };
                }
            }
            string OrderField = "";

            if (OrderFiledmap != default(DataMemberMap))
            {
                OrderField = string.Format("{0}  {1}", OrderFiledmap.DataFieldName, QueryRequest.OrderTypeString());
            }

            string conditionSql = BuildPageQueryWhere(ConditionDataMemberMapList);

            SqlEntityMap <Entity> ep = new SqlEntityMap <Entity>(this.ContractProvider, "[dbo].[P_BM_GenericPage]");

            ep.SetCommandType(System.Data.CommandType.StoredProcedure);

            List <Entity> list =
                ep.AddString("TableName", this.TableName)
                .AddString("Fields", "*")
                .AddInt("pageSize", QueryRequest.PageSize)
                .AddInt("pageIndex", QueryRequest.PageIndex)
                .AddString("OrderField", OrderField)
                .AddString("sqlWhere", conditionSql)
                .AddInt("TotalPage", QueryRequest.TotalPage).SetDirection(ParameterDirection.Output)
                .AddLong("Return", QueryRequest.TotalRecord).SetDirection(ParameterDirection.ReturnValue)
                .AsList(qMap);

            QueryRequest.TotalPage = (int)ep.GetParamValue("TotalPage");
            //Object o = ep.GetParamValue("Return");
            QueryRequest.TotalRecord = long.Parse(ep.GetParamValue("Return").ToString());
            return(list.ToArray());
        }