-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Request] Support for MetadataTypeAttribute #6
Comments
Got this answer by using Chat GPT, can you give it a go? In Entity Framework Core (EF Core), the Code-First approach is more commonly used for defining the model and the database schema based on the code. However, if you are working with an existing database (i.e., a Database-First approach) and you want to use custom attributes with metadata, you can still achieve this by leveraging EF Core's Fluent API. Here's how you can use custom attributes with metadata in a Database-First scenario in EF Core:
public class CustomerMetadata
{
[Required]
public string Name { get; set; }
[MaxLength(100)]
public string Email { get; set; }
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Customer>()
.ForSqlServerHasAnnotation("MyCustomAttribute", "MyValue") // Example of a custom attribute
.HasMetadata<CustomerMetadata>(metadata =>
{
metadata.Property(e => e.Name).HasColumnName("CustomerName");
metadata.Property(e => e.Email).HasColumnName("EmailAddress");
});
} In the code above:
This approach allows you to maintain a separation of concerns by keeping your metadata in separate classes while using the Fluent API to map and configure your database entities when working with a Database-First approach in EF Core. Please note that EF Core's primary approach is Code-First, where you define the model classes and let EF Core generate the database schema. The Database-First approach is less common but is still supported, and you can use the Fluent API to customize the mapping and metadata for entities in this scenario. |
We are using EntityFrameworkCore.PostgreSQL.ColumnEncryption.
I have one request.
I think that "NpgsqlEncrypt" is supposed to be added to the property to be encrypted,
When generating code with "Database first", "NpgsqlEncrypt" cannot be added because the code will be overwritten.
In ASP.NET Core, etc., there is a mechanism to artificially add attributes with "MetadataTypeAttribute" in consideration of this.
I would appreciate it if you could adopt this for EntityFrameworkCore.PostgreSQL.ColumnEncryption as well.
[Code example]
Auto-generated code
Manual add code
The text was updated successfully, but these errors were encountered: