[英]How to use LinqPad with Entity Framework Core?
I feel like I've missed something obvious. 我觉得我错过了一些明显的东西。
I want to test my EF Core DbContext
in LinqPad like I usually do with regular EF. 我想在LinqPad中测试我的EF Core
DbContext
,就像我通常使用常规EF一样。
I have a simple DbContext
: 我有一个简单的
DbContext
:
public class NotificationManagerContext : DbContext
{
public virtual DbSet<Notification> Notifications { get; set; }
}
I've registered it in LinqPad using the new EF Core 2.0.1 driver: 我使用新的EF Core 2.0.1驱动程序在LinqPad中注册了它:
In an MCV Core app I'd register EF and the SQL driver in the app builder and pass it a connection string. 在MCV Core应用程序中,我在应用程序构建器中注册EF和SQL驱动程序,并将其传递给连接字符串。 I don't see how to do the same config in LinqPad?
我不知道如何在LinqPad中进行相同的配置?
In Linqpad there is no dependency injection framework running. 在Linqpad中没有运行依赖注入框架。 So if you want to use a context there you could add a constructor that accepts a connection string.
因此,如果您想使用上下文,您可以添加一个接受连接字符串的构造函数。 You can store the connection string in a member variable —say,
_connString
— and in the OnConfiguring
override of the context do 您可以将连接字符串存储在成员变量-say,
_connString
- 并在上下文的OnConfiguring
覆盖中执行
if (!string.IsNullOrWhiteSpace(_connString))
{
optionsBuilder.UseSqlServer(_connString);
}
That gives you all freedom to play with database connections without having to leave Linqpad. 这使您可以自由地使用数据库连接而无需离开Linqpad。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.