private string BuildQueryString(IDatabase database) { var queryExpression = RelatedMetadata.BuildQueryExpression(database); _primaryKeyIndex = -1; if (RelatedMetadata.PrimaryKeyProperty != null) { var primaryKeyFieldName = RelatedMetadata.GetFieldMetadata(RelatedMetadata.PrimaryKeyProperty).FieldName; int index = 0; foreach (var metadata in RelatedMetadata.AllFieldMetadata.Values) { if (primaryKeyFieldName == metadata.FieldName) { _primaryKeyIndex = index; break; } index++; } } CustomizeQuery(queryExpression); return(database.BuildQueryString(queryExpression)); }
/// <summary> /// Initializes a new instance of the <see cref="DatabaseModelCollectionSearchMetadata{T}"/> class. /// </summary> /// <param name="searchProperty">The property to filter on.</param> /// <param name="searchType">How to filter the data.</param> /// <exception cref="ArgumentException"> /// <paramref name="searchType"/> is not supported /// or /// <paramref name="searchProperty"/> is not a string property. /// </exception> protected DatabaseModelCollectionSearchMetadata(ModelProperty searchProperty, SearchType searchType) { if (searchType == SearchType.None) { throw new ArgumentException("searchType"); } var metadata = RelatedMetadata.GetFieldMetadata(searchProperty) as StringFieldMetadata; if (metadata == null) { throw new ArgumentException("searchProperty does not map to a string field", "searchProperty"); } _searchField = metadata.FieldName; _searchType = searchType; AreResultsReadOnly = true; }