7

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.

I have a simple 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:

enter image description here But what next?

In an MCV Core app I'd register EF and the SQL driver in the app builder and pass it a connection string. I don't see how to do the same config in LinqPad?

Kevin Kuszyk
  • 1,958
  • 24
  • 37
  • Thanks @GertArnold, that did the trick. If you want to post that as an answer I will upvote and mark it as accepted. – Kevin Kuszyk Feb 01 '18 at 12:36

1 Answers1

4

In Linqpad there is no dependency injection framework running. 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

if (!string.IsNullOrWhiteSpace(_connString)) 
{
    optionsBuilder.UseSqlServer(_connString);
}

That gives you all freedom to play with database connections without having to leave Linqpad.

Gert Arnold
  • 105,341
  • 31
  • 202
  • 291