Sometimes it’s useful to derive my entities from a base class like this:
public abstract class DestructableBase : IDestructable
{
/// <summary>
/// If true, this object should be deleted from the database.
/// </summary>
[NotMapped]
public bool _destroy { get; set; }
}
This allows a web client to mark an entity as needing to be deleted when data is posted back to the server. Obviously I do not wish to record such a property in the database though, so I use the [NotMapped] attribute.
I’ve begun using the fluent API more and more to do my configurations though and would like to stop using data annotations. Is there a way to use the fluent API to do this without having to set Ignore() on every entity individually? Or is there a better way altogether?
You can try to use this class as a base class for your entity configurations:
Now every other entity derived from
DestructableBaseneeds entity configuration class derived fromDestructableBaseConfiguration. You will register your configurations tomodelBuilderinOnModelCreating.