我先做数据库,EF 生成了 Code First DbContext 子类...
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Glossary.UI.Database
{
using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
public partial class GlossaryDb : DbContext
{
public GlossaryDb()
: base("name=GlossaryDb")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public DbSet<GlossaryTerm> GlossaryTerms { get; set; }
}
}
如您所见,它引发了异常,因此每次重新生成代码时我都需要将其注释掉!更重要的是,为什么它会生成这个类?