I am building an ASP.NET Core Web API with EF Core 7, and am using a code-first approach. One of my classes has a lambda property TitleNormalized, and I want it to appear as a column in my SQL Server table. When I migrate it, the column does not appear (however, it does appear when the GET request is serialized via OpenAPI).
This is what my class looks like:
[Index(nameof(Title))]
public class Artwork : BaseObject
{
public string Title { get; set; } = string.Empty;
public string TitleNormalized => StringExtensions.NormalizeString(Title) ?? string.Empty;
}
public class ArtworkEntityTypeConfiguration : BaseObjectTypeConfiguration<Artwork>
{
public override void Configure(EntityTypeBuilder<Artwork> builder)
{
//// Max Length
builder
.Property(b => b.Title)
.HasMaxLength(500);
base.Configure(builder);
}
}
How should I rewrite this so a column gets created and autopopulated in SQL Server?