如何在实体框架核心中使用LinqPad?

Kev*_*zyk 6 c# entity-framework linqpad entity-framework-core .net-core

我感觉好像错过了一些明显的事情。

我想像DbContext通常使用常规EF一样在LinqPad中测试我的EF Core 。

我有一个简单的DbContext

public class NotificationManagerContext : DbContext
{
    public virtual DbSet<Notification> Notifications { get; set; }        
}
Run Code Online (Sandbox Code Playgroud)

我已经使用新的EF Core 2.0.1驱动程序在LinqPad中注册了它:

在此处输入图片说明 但是接下来呢?

在MCV Core应用程序中,我将在应用程序构建器中注册EF和SQL驱动程序,并将其传递给连接字符串。我看不到如何在LinqPad中执行相同的配置?

Ger*_*old 5

在 Linqpad 中,没有运行依赖注入框架。因此,如果您想在那里使用上下文,您可以添加一个接受连接字符串的构造函数。您可以将连接字符串存储在成员变量 \xe2\x80\x94say、_connString\xe2\x80\x94 中,并在OnConfiguring上下文的覆盖中执行

\n\n
if (!string.IsNullOrWhiteSpace(_connString)) \n{\n    optionsBuilder.UseSqlServer(_connString);\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

这使您可以自由地使用数据库连接,而无需离开 Linqpad。

\n