How to run SQLite EFCore 2.0 in LinqPad?

a simple code I was trying to help from StackOveflow:

nuget packages used:

Microsoft.EntityFrameworkCore
Microsoft.EntityFrameworkCore.Sqlite

program in C#

----
void Main()
{
var connection = new Microsoft.Data.Sqlite.SqliteConnection("DataSource=:memory:");

connection.Open();

var options = new Microsoft.EntityFrameworkCore.DbContextOptionsBuilder()
.UseSqlite(connection)
.Options;

var context = new TestDbContext(options);

context.Database.EnsureCreated();

var items = new List
{
new Item{Id = 1, Name = "Item 1", Price = 100},
new Item{Id = 2, Name = "Item 2", Price = 10},
new Item{Id = 3, Name = "Item 3", Price = 0},
new Item{Id = 4, Name = "Item 4", Price = -1},
new Item{Id = 5, Name = "Item 5", Price = -5}
};

var query1 = items.Where(x => x.Price > 0).Select(x => x.Name);
var results1 = query1.ToArray();
($"Items with price greater than 0 - {string.Join(",", results1)}").Dump("results 1");

var query2 = items.Where(x => x.Price > -1m).Select(x => x.Name);
var results2 = query2.ToArray();
($"Items with price greater than -1 - {string.Join(",", results2)}").Dump("results 2");

var query3 = items.Where(x => decimal.Negate(x.Price) < 1).Select(x => x.Name);
var results3 = query3.ToArray();
($"Items with price greater than -1 - {string.Join(",", results3)}").Dump("results 3");
}

public class Item
{
public long Id { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
}

class TestDbContext : Microsoft.EntityFrameworkCore.DbContext
{
public TestDbContext(Microsoft.EntityFrameworkCore.DbContextOptions options) : base(options) { }
public Microsoft.EntityFrameworkCore.DbSet Items { get; set; }
}
----

I get an error:

> Unable to load DLL 'e_sqlite3': The specified module could not be found.

before I was getting

> Could not load file or assembly 'SQLitePCLRaw.provider.e_sqlite3...

but I could, somehow, move along

Thank you.

Comments

  • edited February 21
    I don't know. Try to find online the the best solution for it
  • So this was bugging me as well. Here is how I got it working.
    I happen to have a 4.7.1 project which was using the context as well. From the output folder of that project, I copied the following into the same directory as Linqpad. Maybe some of these are extra, but I was just happy to have it working, and not feeling like messing with it further.

    SQLitePCLRaw.batteries_green.dll
    SQLitePCLRaw.batteries_v2.dll
    SQLitePCLRaw.core.dll
    SQLitePCLRaw.provider.e_sqlite3.dll
    x64\
    x86\
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!