public MappedObject GetMapping(string entityType, int id) { entityType = entityType.ToLowerInvariant(); MappedObject map = null; if (this.EntityMaps.Count > 0) { var entity = this.EntityMaps.Find(e => e.EntityType.EqualsIgnoreCase(entityType)); if (entity != null) { map = entity.MappedObjects.Find(m => m.ID == id); } } else { map = MappedObject.Find(this.StoreID, entityType, id); } return(map); }
/// <summary> /// Gets the mapped object /// </summary> /// <param name="storeId"></param> /// <param name="type"></param> /// <param name="id"></param> /// <returns></returns> public static MappedObject Find(int storeId, string type, int id) { MappedObject map = null; Action <IDataReader> readAction = (rs) => { if (rs.Read()) { map = new MappedObject(); map.ID = rs.FieldInt("ID"); map.StoreID = storeId; map.Type = rs.Field("EntityType"); map.Name = rs.Field("Name"); map.IsMapped = rs.FieldBool("Mapped"); } }; string findQuery = "dbo.aspdnsf_GetMappedObject @StoreId = {0}, @EntityType = {1}, @EntityID = {2}".FormatWith(storeId, type.DBQuote(), id); DB.UseDataReader(findQuery, readAction); return(map); }
/// <summary> /// Checks to determine if a particular entity is mapped to the store /// </summary> /// <param name="entityType">Type of entity</param> /// <param name="id">Entity ID</param> /// <returns></returns> public bool IsMapped(string entityType, int id) { MappedObject map = GetMapping(entityType, id); return(map != null && map.IsMapped); }