#[entity]Expand description
Attribute macro for impl IEntityTypeConfiguration<T> blocks.
Emits an inventory::submit! registering the configuration for automatic
discovery by DbContext::from_options(). The first argument is the entity
type T; the config type is taken from the impl’s Self type. An
optional second argument specifies the DbContext key for multi-database
scenarios.
§Examples
ⓘ
#[derive(Default)]
pub struct BlogConfig;
// Default context
#[entity(Blog)]
impl IEntityTypeConfiguration<Blog> for BlogConfig {
fn configure(&self, entity: &mut EntityTypeBuilder<'_, Blog>) {
entity.to_table("blogs_renamed");
}
}
// Keyed context ("logs" database)
#[entity(LogEntry, "logs")]
impl LogEntryConfig for IEntityTypeConfiguration<LogEntry> {
fn configure(&self, entity: &mut EntityTypeBuilder<'_, LogEntry>) {
entity.to_table("app_logs");
}
}