I'm using standards for singular table names. EF4 Code First has by default to pluralize table names. I have put the code to override this convention, but seems is not working.
using section:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity;
using System.Data.Entity.Database;
using System.Data.Entity.ModelConfiguration;
using System.Data.Entity.ModelConfiguration.Conventions.Edm;
Data context:
public class SiteDataContext : DbContext
{
public DbSet<Blog> Blogs { get; set; }
public DbSet<BlogFeedback> BlogFeedbacks { get; set; }
public DbSet<BlogCategory> BlogCategories { get; set; }
// Twist our database
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingEntitySetNameConvention>();
base.OnModelCreating(modelBuilder);
}
}
Tables created:
When because the convention override (and what I need) should be:
Anyone has an idea why the override line is not working? Thanks a lot.
Your using the wrong convention. You need to do the below.
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With