【发布时间】:2011-05-05 13:40:34
【问题描述】:
我正在使用单数表名的标准。默认情况下,EF4 Code First 具有复数表名。我已将代码覆盖此约定,但似乎无法正常工作。
使用部分:
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;
数据上下文:
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);
}
}
创建的表:
- 博客
- 博客反馈
- 博客类别
什么时候因为约定覆盖(以及我需要什么)应该是:
- 博客
- 博客反馈
- 博客类别
任何人都知道为什么覆盖线不起作用?非常感谢。
【问题讨论】:
标签: entity-framework-4 ef-code-first entity-framework-ctp5