Mid From PDF EF Core Entity Framework Core

How do you configure mappings (table names, column names, keys) using Data Annotations vs Fluent API?

🧩 Data Annotations (in the entity class):

[Table("Users")]

public class User
{

[Key]

public int Id { get; set; }

[Column("UserName")]

public string Name { get; set; }
}

🧠 Fluent API (in OnModelCreating):

modelBuilder.Entity<User>()

.ToTable("Users")

.HasKey(u => u.Id);

modelBuilder.Entity<User>()

.Property(u => u.Name)

.HasColumnName("UserName");

📌 Fluent API is more powerful and flexible, preferred for complex configurations.

More from Entity Framework Core Tutorial

All questions for this course
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details