public TypedListMetaDetailsResponse GetTypedListMetaDetails(ServiceStack.ServiceInterface.Service service) { // The entity meta details don't change per type, so cache these for performance var cacheKey = string.Format("{0}-typedlist-meta-details", TypedListType.ToString().ToLower()); var metaDetails = CacheClient.Get <TypedListMetaDetailsResponse>(cacheKey); if (metaDetails != null) { return(metaDetails); } var request = service.RequestContext.Get <IHttpRequest>(); var appUri = request.GetApplicationUrl().TrimEnd('/'); var baseServiceUri = appUri + request.PathInfo.Replace("/meta", ""); var queryString = request.QueryString["format"] != null ? "&format=" + request.QueryString["format"] : ""; var pkCount = FieldMap.Count(pk => pk.Value.IsPrimaryKey); var fields = new List <Link>(); var fieldIndex = -1; foreach (var f in FieldMap) { fieldIndex++; var isUnique = false; var link = Link.Create( f.Key.ToCamelCase(), f.Value.DataType.Name, "field", string.Format("{0}?select={1}{2}", baseServiceUri, f.Key.ToLowerInvariant(), queryString), string.Format("The {0} field for the {1} resource.", f.Value.Name, typeof(TDto).Name), new Dictionary <string, string>() ); var props = new SortedDictionary <string, string>(); props.Add("index", fieldIndex.ToString() /*WRONG: f.Value.FieldIndex.ToString(CultureInfo.InvariantCulture)*/); if (f.Value.IsPrimaryKey) { props.Add("isPrimaryKey", f.Value.IsPrimaryKey.ToString().ToLower()); if (pkCount == 1) { isUnique = true; } } if (f.Value.IsForeignKey) { props.Add("isForeignKey", "true"); } if (isUnique) { props.Add("isUnique", "true"); } if (f.Value.IsOfEnumDataType) { props.Add("isOfEnumDataType", "true"); } if (f.Value.IsReadOnly) { props.Add("isReadOnly", "true"); } if (f.Value.IsNullable) { props.Add("isNullable", "true"); } if (f.Value.IsOfEnumDataType) { props.Add("isEnumType", "true"); } if (f.Value.MaxLength > 0) { props.Add("maxLength", f.Value.MaxLength.ToString(CultureInfo.InvariantCulture)); } if (f.Value.Precision > 0) { props.Add("precision", f.Value.Precision.ToString(CultureInfo.InvariantCulture)); } if (f.Value.Scale > 0) { props.Add("scale", f.Value.Scale.ToString(CultureInfo.InvariantCulture)); } link.Properties = new Dictionary <string, string>(props); fields.Add(link); } metaDetails = new TypedListMetaDetailsResponse() { Fields = fields.ToArray(), }; CacheClient.Set(cacheKey, metaDetails); return(metaDetails); }
partial void OnAfterGetEmployeesByRegionAndTerritoryMetaRequest(EmployeesByRegionAndTerritoryMetaRequest request, TypedListMetaDetailsResponse response);