此代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration;
namespace ArticleLibrary_.NET.Models
{
public class ArticleLibraryEntitiy : DbContext
{
public DbSet<Post> Posts { get; set; }
public DbSet<Person> People { get; set; }
public DbSet<Tag> Tags { get; set; }
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
}
}
错误地说:
Expected class, delegate, enum, interface, or struct
在行
protected override void OnModelCreating(ModelBuilder modelBuilder)
并且VS代码编辑器
也无法识别ModelBuilder
我是否必须添加任何其他参考?
答案 0 :(得分:7)
您必须在类中编写OnModelCreating
函数。你在它下面写下来。将您的代码更改为:
namespace ArticleLibrary_.NET.Models
{
public class ArticleLibraryEntitiy : DbContext
{
public DbSet<Post> Posts { get; set; }
public DbSet<Person> People { get; set; }
public DbSet<Tag> Tags { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
}
}
}