gpt4 book ai didi

asp.net - 无法添加方法 OnModelCreating

转载 作者:行者123 更新时间:2023-12-02 10:18:40 25 4
gpt4 key购买 nike

这段代码

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

我需要添加任何其他引用吗?

最佳答案

您必须在类中编写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)
{

}
}

}

关于asp.net - 无法添加方法 OnModelCreating,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9989780/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com