Class Extensions
Extension methods for entities
public static class Extensions
- Inheritance
-
Extensions
- Inherited Members
Methods
DeleteAllAsync<T>(IEnumerable<T>, DB, CancellationToken)
Deletes multiple entities from the database
HINT: If these entities are referenced by one-to-many/many-to-many relationships, those references are also deleted.
public static Task<DeleteResult> DeleteAllAsync<T>(this IEnumerable<T> entities, DB db, CancellationToken cancellation = default) where T : IEntity
Parameters
entitiesIEnumerable<T>dbDBThe DB instance to use for this operation
cancellationCancellationTokenAn optional cancellation token
Returns
- Task<DeleteResult>
Type Parameters
T
DeleteAsync<T>(T, DB, CancellationToken)
Deletes a single entity from MongoDB.
HINT: If this entity is referenced by one-to-many/many-to-many relationships, those references are also deleted.
public static Task<DeleteResult> DeleteAsync<T>(this T entity, DB db, CancellationToken cancellation = default) where T : IEntity
Parameters
entityTdbDBThe DB instance to use for this operation
cancellationCancellationTokenAn optional cancellation token
Returns
- Task<DeleteResult>
Type Parameters
T
Distinct<T>(IAggregateFluent<T>)
Adds a distinct aggregation stage to a fluent pipeline.
public static IAggregateFluent<T> Distinct<T>(this IAggregateFluent<T> aggregate) where T : IEntity
Parameters
aggregateIAggregateFluent<T>
Returns
- IAggregateFluent<T>
Type Parameters
TAny class that implements IEntity
DropAsync(IMongoCollection<JoinRecord>)
Drops a join collection
public static Task DropAsync(this IMongoCollection<JoinRecord> collection)
Parameters
collectionIMongoCollection<JoinRecord>
Returns
ExistsAsync(IMongoDatabase, int)
Checks to see if the database already exists on the mongodb server
public static Task<bool> ExistsAsync(this IMongoDatabase db, int timeoutSeconds = 5)
Parameters
dbIMongoDatabasetimeoutSecondsintThe number of seconds to keep trying
Returns
FullPath<T>(Expression<Func<T, object?>>)
Returns the full dotted path of a property for the given expression
public static string FullPath<T>(this Expression<Func<T, object?>> expression)
Parameters
expressionExpression<Func<T, object>>
Returns
Type Parameters
TAny class that implements IEntity
InitManyToMany<TChild, TParent>(IEntity, Expression<Func<Many<TChild, TParent>?>>, Expression<Func<TChild, object>?>, DB?)
Initializes supplied property with a new Many-To-Many relationship.
public static void InitManyToMany<TChild, TParent>(this IEntity parent, Expression<Func<Many<TChild, TParent>?>> propertyToInit, Expression<Func<TChild, object>?> propertyOtherSide, DB? db = null) where TChild : IEntity where TParent : IEntity
Parameters
parentIEntitypropertyToInitExpression<Func<Many<TChild, TParent>>>() = > PropertyName
propertyOtherSideExpression<Func<TChild, object>>x => x.PropertyName
dbDBthe DB instance to work with
Type Parameters
TChildTParent
InitOneToMany<TChild, TParent>(TParent, Expression<Func<Many<TChild, TParent>?>>, DB?)
Initializes supplied property with a new One-To-Many relationship.
public static void InitOneToMany<TChild, TParent>(this TParent parent, Expression<Func<Many<TChild, TParent>?>> propertyToInit, DB? db = null) where TChild : IEntity where TParent : IEntity
Parameters
parentTParentpropertyToInitExpression<Func<Many<TChild, TParent>>>() => PropertyName
dbDBthe database instance to work with
Type Parameters
TChildTParent
IsAccessibleAsync(IMongoDatabase, int)
Pings the mongodb server to check if it's still connectable
public static Task<bool> IsAccessibleAsync(this IMongoDatabase db, int timeoutSeconds = 5)
Parameters
dbIMongoDatabasetimeoutSecondsintThe number of seconds to keep trying
Returns
MatchExpression<T>(IAggregateFluent<T>, string)
Appends a match stage to the pipeline with an aggregation expression (i.e. $expr)
public static IAggregateFluent<T> MatchExpression<T>(this IAggregateFluent<T> aggregate, string expression) where T : IEntity
Parameters
aggregateIAggregateFluent<T>expressionstring{ $gt: ['$Property1', '$Property2'] }
Returns
- IAggregateFluent<T>
Type Parameters
TAny class that implements IEntity
Match<T>(IAggregateFluent<T>, Func<FilterDefinitionBuilder<T>, FilterDefinition<T>>)
Appends a match stage to the pipeline with a filter expression
public static IAggregateFluent<T> Match<T>(this IAggregateFluent<T> aggregate, Func<FilterDefinitionBuilder<T>, FilterDefinition<T>> filter) where T : IEntity
Parameters
aggregateIAggregateFluent<T>filterFunc<FilterDefinitionBuilder<T>, FilterDefinition<T>>f => f.Eq(x => x.Prop, Value) & f.Gt(x => x.Prop, Value)
Returns
- IAggregateFluent<T>
Type Parameters
TAny class that implements IEntity
SortByRelevance<T>(IEnumerable<T>, string, Func<T, string>, int?)
Sort a list of objects by relevance to a given string using Levenshtein Distance
public static IEnumerable<T> SortByRelevance<T>(this IEnumerable<T> objects, string searchTerm, Func<T, string> propertyToSortBy, int? maxDistance = null)
Parameters
objectsIEnumerable<T>The list of objects to sort
searchTermstringThe term to measure relevance to
propertyToSortByFunc<T, string>x => x.PropertyName [the term will be matched against the value of this property]
maxDistanceint?The maximum levenstein distance to qualify an item for inclusion in the returned list
Returns
- IEnumerable<T>
Type Parameters
TAny object type
ToBatches<T>(IEnumerable<T>, int)
Extension method for processing collections in batches with streaming (yield return)
public static IEnumerable<IEnumerable<T>> ToBatches<T>(this IEnumerable<T> collection, int batchSize = 100)
Parameters
collectionIEnumerable<T>The source collection
batchSizeintThe size of each batch
Returns
Type Parameters
TThe type of the objects inside the source collection
ToDate(DateTime)
public static Date ToDate(this DateTime dateTime)
Parameters
Returns
ToDate(long)
converts ticks to a Date instance.
public static Date ToDate(this long ticks)
Parameters
tickslongthe ticks to convert
Returns
ToDocument<T>(T)
Creates an unlinked duplicate of the original IEntity ready for embedding with a blank ID.
public static T ToDocument<T>(this T entity) where T : IEntity
Parameters
entityT
Returns
- T
Type Parameters
T
ToDocuments<T>(IEnumerable<T>, DB?)
Creates unlinked duplicates of the original Entities ready for embedding with blank IDs.
public static IEnumerable<T> ToDocuments<T>(this IEnumerable<T> entities, DB? dbInstance = null) where T : IEntity
Parameters
entitiesIEnumerable<T>dbInstanceDB
Returns
- IEnumerable<T>
Type Parameters
T
ToDocuments<T>(T[], DB?)
Creates unlinked duplicates of the original Entities ready for embedding with blank IDs.
public static T[] ToDocuments<T>(this T[] entities, DB? dbInstance = null) where T : IEntity
Parameters
entitiesT[]dbInstanceDB
Returns
- T[]
Type Parameters
T
ToDoubleMetaphoneHash(string)
Converts a search term to Double Metaphone hash code suitable for fuzzy text searching.
public static string ToDoubleMetaphoneHash(this string term)
Parameters
termstringA single or multiple word search term
Returns
ToFuzzy(string)
converts a string value to a FuzzyString
public static FuzzyString ToFuzzy(this string value)
Parameters
valuestringthe string to convert
Returns
ToReference<T>(T)
Returns a reference to this entity.
public static One<T> ToReference<T>(this T entity) where T : IEntity
Parameters
entityT
Returns
- One<T>
Type Parameters
T