我开始了新的剃刀项目,我想使用mysql作为服务器。我按照官方示例使用实体official example和这个one连接mysql。这里少了什么?
错误CS1061:“DbContextOptionsBuilder”不包含“UseMysql”的定义
using Microsoft.EntityFrameworkCore;
using MySql.EntityFrameworkCore.Extensions;
using Database.Entities;
namespace Database;
public class ApplicationContext : DbContext
{
public DbSet<User> Users { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder builder)
=> builder.UseMysql("server=localhost;database=razor;username=root;password=VuYbe*$LnjhET%IM)g7qPvZ6KQ@F#!Hr53^Bk(dGWRxXCJzaw4ft8Ns&D9pyA2m+");
}
文件.csproj
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.10">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="MySql.Data" Version="8.0.31" />
<PackageReference Include="MySql.EntityFrameworkCore" Version="6.0.7" />
</ItemGroup>
1条答案
按热度按时间v8wbuo2f1#
试试这个
标准做法是将Depedency Injection的扩展方法放入Microsoft.Extensions。DependencyInjection命名空间,它包含在大多数ASP中。NETCore应用程序项目,因此当导入包时,该方法将自动可用。