Gab*_*lls 5 c# sqlite entity-framework-core uwp
我是 UWP 的新手,我正在尝试设置我的项目以使用 SQLite 数据库,我正在使用 Microsoft.EntityFrameworkCore.SQLite。
当我尝试设置数据库上下文时,我不断收到此错误。
DbContextOptionsBuilder 不包含 UseSqlite 的定义,并且找不到接受 DBcontextoptionsbuilder 类型的第一个参数的可访问扩展方法(您是使用指令还是程序集引用)
这是我的代码
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BradamaInternationalSkill.Models
{
/// <summary>
/// The Entity Framework Database Context.
/// </summary>
public class PersonContext : DbContext
{
internal DbSet<Person> People { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite("Filename=People.db");
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// Make Id required.
modelBuilder.Entity<Person>()
.Property(p => p.Id)
.IsRequired();
// Make Name required.
modelBuilder.Entity<Person>()
.Property(p => p.Name)
.IsRequired();
}
}
}
Run Code Online (Sandbox Code Playgroud)
我通过卸载 Nuget 包“Microsoft Entity Framework Core”并安装“Entity.Framework.Core.Sqlite.Design”解决了这个问题。我不知道为什么它解决了这个问题,但错误消失了,我很高兴,这才是最重要的。
| 归档时间: |
|
| 查看次数: |
1371 次 |
| 最近记录: |