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()); }
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; }
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; }
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; }
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; }
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; }
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; }
/// <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); }
public IEnumerable <T> AsEnumerable(ResultMapDelegate <T> map) { _mapper = map; return(AsEnumerable()); }
public List <T> AsList(ResultMapDelegate <T> map) { _mapper = map; return(AsList()); }
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()); }