Provides Entity Framework Core integration for the EmailAddress value object from
PosInformatique.Foundations.EmailAddresses.
This package enables seamless mapping of RFC 5322 compliant email addresses as strongly-typed properties in Entity Framework Core entities.
It ensures proper SQL type mapping, validation, and conversion to VARCHAR when persisted to the database.
You can install the package from NuGet:
dotnet add package PosInformatique.Foundations.EmailAddresses.EntityFrameworkThis package depends on the base package PosInformatique.Foundations.EmailAddresses.
- Provides an extension method
IsEmailAddress()to configure EF Core properties forEmailAddress. - Maps to
VARCHAR(320)database columns using the SQL typeEmailAddress(you must define the SQL typeEmailAddressmapped toVARCHAR(320)in your database). - Ensures validation, normalization, and safe conversion to/from database fields.
- Built on top of the core
EmailAddressvalue object.
- Entity mapping: enforce strong typing for email addresses at the persistence layer.
- Consistency: ensure the same validation rules are applied in your entities and database.
- Safety: prevent invalid strings being stored in your database
⚠️ To useIsEmailAddress(), you must first define the SQL typeEmailAddressmapped toVARCHAR(320)in your database.
For SQL Server, you can create it with:
CREATE TYPE EmailAddress FROM VARCHAR(320) NOT NULL;using Microsoft.EntityFrameworkCore;
using PosInformatique.Foundations;
public class User
{
public int Id { get; set; }
public EmailAddress Email { get; set; }
}
public class ApplicationDbContext : DbContext
{
public DbSet<User> Users => Set<User>();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<User>()
.Property(u => u.Email)
.IsEmailAddress();
}
}This will configure the Email property of the User entity with:
VARCHAR(320)(Non-unicode) column length- SQL column type
EmailAddress