【发布时间】:2021-07-17 22:25:32
【问题描述】:
我正在尝试使用 ServiceStack.OrmLite 版本 5.11.0 based on the follow article from 2016 在 C# 中编写一个 Sqlite 内存数据库,其中包含一个名为 InMemoryDatabase 的类,如下所示:
using ServiceStack.OrmLite;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
namespace akmazio_api.Classes
{
public class InMemoryDatabase
{
private readonly OrmLiteConnectionFactory dbFactory = new(":memory:", SqliteOrmLiteDialectProvider.Instance);
public IDbConnection OpenConnection() => dbFactory.OpenDbConnection();
public void Insert<T>(IEnumerable<T> items)
{
using var db = OpenConnection();
db.CreateTableIfNotExists<T>();
foreach (var item in items)
{
db.Insert(item);
}
}
}
}
我遇到的问题是SqliteOrmLiteDialectProvider 类名下方出现红色波浪线,而我得到的编译器错误是:
CS0103: The name 'SqliteOrmLiteDialectProvider' does not exist in the current context
这里有人知道如何解决这个问题,以便我可以在我的 C# 应用程序中启动并运行一个 Sqlite 实例吗?
如果您需要任何其他信息来解决此问题,请告诉我。
【问题讨论】:
标签: c# database sqlite unit-testing ormlite-servicestack