sqlite不使用视图efcore dbcontext

发布于 2025-01-21 07:27:04 字数 390 浏览 2 评论 0原文

我有一个使用SQLITE作为数据库伪造的单元测试项目。

除了视图外,一切都可以。它返回例外

sqlite错误1:'否这样的表:用户删除。

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    base.OnModelCreating(modelBuilder);
    modelBuilder
         .Entity<UserDetail>()
         .ToView(nameof(UserDetails))
         .HasNoKey();
}

有人有解决方案吗? 提前致谢。

I have an Unit Test Project using SQLite as the database fake.

Everything Ok except with the View. It returns an exception

SQLite Error 1: 'no such table: UserDetails'.

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    base.OnModelCreating(modelBuilder);
    modelBuilder
         .Entity<UserDetail>()
         .ToView(nameof(UserDetails))
         .HasNoKey();
}

Does anyone have the solution?
Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冰雪之触 2025-01-28 07:27:04

您是否在数据库中定义了视图?

如果您使用的是迁移,则可以在up方法中添加这样的行。

migrationBuilder.Sql(@"
    CREATE VIEW UserDetails AS
    -- TODO: Write the actual SELECT statement
    SELECT 1;
");

Have you defined the view in your database?

If you're using Migrations, you can add a line like this in the Up method.

migrationBuilder.Sql(@"
    CREATE VIEW UserDetails AS
    -- TODO: Write the actual SELECT statement
    SELECT 1;
");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文