Interface ICollectionMigration<TEntity>
Fluent, typed operations against a single entity's collection/container.
public interface ICollectionMigration<TEntity> where TEntity : class
Type Parameters
TEntityThe entity type.
Methods
AddField<TField>(Expression<Func<TEntity, TField>>)
Adds the stored column for an entity member to an existing table. The member already exists on the entity (and therefore in the model); this evolves the live schema to match. Document stores gain fields on write, so the operation is a no-op there.
ICollectionMigration<TEntity> AddField<TField>(Expression<Func<TEntity, TField>> field)
Parameters
fieldExpression<Func<TEntity, TField>>The member selector.
Returns
- ICollectionMigration<TEntity>
Type Parameters
TFieldThe field type.
CompositeIndex(Action<IIndexKeyBuilder<TEntity>>, bool)
Ensures a composite (multi-key) index exists.
ICollectionMigration<TEntity> CompositeIndex(Action<IIndexKeyBuilder<TEntity>> keys, bool unique = false)
Parameters
keysAction<IIndexKeyBuilder<TEntity>>The fluent key builder (e.g.
k => k.Descending(x => x.A).Ascending(x => x.B)).uniqueboolWhether the index enforces uniqueness.
Returns
- ICollectionMigration<TEntity>
ConvertField<TField>(Expression<Func<TEntity, TField>>, MigrationFieldType, MigrationFieldType)
Converts a field's stored type across existing documents (type/schema evolution).
ICollectionMigration<TEntity> ConvertField<TField>(Expression<Func<TEntity, TField>> field, MigrationFieldType from, MigrationFieldType to)
Parameters
fieldExpression<Func<TEntity, TField>>The field selector.
fromMigrationFieldTypeThe current stored type.
toMigrationFieldTypeThe target stored type.
Returns
- ICollectionMigration<TEntity>
Type Parameters
TFieldThe field type.
DropCollection(string)
Drops the collection, and everything in it. Nothing checks that this is the one you meant.
ICollectionMigration<TEntity> DropCollection(string name)
Parameters
namestringThe stored name of the collection.
Returns
- ICollectionMigration<TEntity>
DropField(string)
Drops a stored column/field by its stored name — the CLR member is usually already gone, so the name is a string here by design. On document stores this unsets the field across documents.
ICollectionMigration<TEntity> DropField(string field)
Parameters
fieldstringThe stored column/field name.
Returns
- ICollectionMigration<TEntity>
EnsureCollection()
Ensures the collection/container exists.
ICollectionMigration<TEntity> EnsureCollection()
Returns
- ICollectionMigration<TEntity>
Index<TField>(Expression<Func<TEntity, TField>>, Action<IIndexOptions<TEntity>>)
Ensures a single-key index exists with rich, provider-interpreted options — a typed partial filter
(o.Filtered(x => x.DeletedAt == null)), a structure (o.Gin(), o.Text()), a TTL
(o.Ttl(...)) — each rejected with guidance by providers that cannot build it.
ICollectionMigration<TEntity> Index<TField>(Expression<Func<TEntity, TField>> field, Action<IIndexOptions<TEntity>> options)
Parameters
fieldExpression<Func<TEntity, TField>>The field selector.
optionsAction<IIndexOptions<TEntity>>The fluent index options.
Returns
- ICollectionMigration<TEntity>
Type Parameters
TFieldThe field type.
Index<TField>(Expression<Func<TEntity, TField>>, bool, bool)
Ensures a single-key index exists.
ICollectionMigration<TEntity> Index<TField>(Expression<Func<TEntity, TField>> field, bool descending = false, bool unique = false)
Parameters
fieldExpression<Func<TEntity, TField>>The field selector (e.g.
x => x.CreatedAt).descendingboolWhether the key is descending.
uniqueboolWhether the index enforces uniqueness.
Returns
- ICollectionMigration<TEntity>
Type Parameters
TFieldThe field type.
RenameCollection(string, string)
Renames the collection this entity is stored in.
ICollectionMigration<TEntity> RenameCollection(string currentName, string newName)
Parameters
Returns
- ICollectionMigration<TEntity>
RenameField(string, string)
Renames a field, naming both sides outright.
Use this when the model has already moved on — which is always the case for a generated migration. The selector overload asks the model what the field is called today, and once the mapping has changed that answer is the new name, so the rename would resolve to a no-op while the old name stays in the store. Stating both sides describes the transition instead of the destination.
ICollectionMigration<TEntity> RenameField(string currentName, string newName)
Parameters
Returns
- ICollectionMigration<TEntity>
RenameField<TField>(Expression<Func<TEntity, TField>>, string)
Renames a field across existing documents.
ICollectionMigration<TEntity> RenameField<TField>(Expression<Func<TEntity, TField>> field, string newName)
Parameters
fieldExpression<Func<TEntity, TField>>The field selector, whose current name is read from the model.
newNamestringThe new field name.
Returns
- ICollectionMigration<TEntity>
Type Parameters
TFieldThe field type.
ResizeField<TField>(Expression<Func<TEntity, TField>>)
Restates a field's stored type to the one the model declares — how a varchar(50) becomes a
varchar(200). The size is read from the model, so there is nothing to pass but the field.
A document store has no declared size, so this does nothing there rather than pretending to.
ICollectionMigration<TEntity> ResizeField<TField>(Expression<Func<TEntity, TField>> field)
Parameters
fieldExpression<Func<TEntity, TField>>The field selector.
Returns
- ICollectionMigration<TEntity>
Type Parameters
TFieldThe field type.
Update(Expression<Func<TEntity, bool>>, Action<IUpdateBuilder<TEntity>>)
Applies assignments to the documents matching a predicate (a data migration).
ICollectionMigration<TEntity> Update(Expression<Func<TEntity, bool>> predicate, Action<IUpdateBuilder<TEntity>> update)
Parameters
predicateExpression<Func<TEntity, bool>>The predicate selecting the documents.
updateAction<IUpdateBuilder<TEntity>>The fluent assignment builder.
Returns
- ICollectionMigration<TEntity>