Closed
Description
I try to execute this EF code but not success. I guess there is a native DLL was not load correctly into dotnet-script but I have no idea how to fix.
Script Db.csx
#! "netcoreapp2.0"
#r "nuget:NetStandard.Library,2.0.0"
#r "nuget:Microsoft.EntityFrameworkCore,2.0.1"
#r "nuget:Microsoft.EntityFrameworkCore.Sqlite,2.0.1"
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
class Order {
public int Id { set;get; }
public List<OrderDetail> Details { set; get; } = new List<OrderDetail>();
}
class OrderDetail {
public int Id { set;get; }
public string Product { set;get; }
}
class OrderContext : DbContext {
public DbSet<Order> Orders { set;get; }
public DbSet<OrderDetail> OrderDetails { set;get; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) {
optionsBuilder.UseSqlite("Data Source=Order.db");
}
}
var context = new OrderContext();
context.Database.EnsureCreated();
context.Orders.Add(new Order { });
context.SaveChanges();
Output Message
❯ dotnet script "./scripts/Db.csx"
System.TypeInitializationException: The type initializer for 'Microsoft.Data.Sqlite.SqliteConnection' threw an exception. ---> System.Reflection.TargetInvo
cationException: Exception has been thrown by the target of an invocation. ---> System.DllNotFoundException: Unable to load DLL 'e_sqlite3': The specified
module or one of its dependencies could not be found.
(Exception from HRESULT: 0x8007007E)
at SQLitePCL.SQLite3Provider_e_sqlite3.NativeMethods.sqlite3_libversion_number()
at SQLitePCL.SQLite3Provider_e_sqlite3.SQLitePCL.ISQLite3Provider.sqlite3_libversion_number()
at SQLitePCL.raw.SetProvider(ISQLite3Provider imp)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at Microsoft.Data.Sqlite.Utilities.BundleInitializer.Initialize()
at Microsoft.Data.Sqlite.SqliteConnection..cctor()
--- End of inner exception stack trace ---
at Microsoft.EntityFrameworkCore.Storage.Internal.SqliteRelationalConnection.CreateDbConnection()
at Microsoft.EntityFrameworkCore.Internal.LazyRef`1.get_Value()
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open(Boolean errorsExpected)
at Microsoft.EntityFrameworkCore.Storage.Internal.SqliteRelationalConnection.Open(Boolean errorsExpected)
at Microsoft.EntityFrameworkCore.Storage.Internal.SqliteDatabaseCreator.Exists()
at Microsoft.EntityFrameworkCore.Storage.RelationalDatabaseCreator.EnsureCreated()
at Submission#0.<<Initialize>>d__0.MoveNext() in /Users/wk/Source/DotNetEF/scripts/Db.csx:line 28
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.CodeAnalysis.Scripting.ScriptExecutionState.<RunSubmissionsAsync>d__9`1.MoveNext()
Metadata
Metadata
Assignees
Labels
No labels