SQLite database access with EFCore from Electron.NET ASP NET Core does not work #590

Closed
opened 2026-01-29 16:43:32 +00:00 by claunia · 2 comments
Owner

Originally created by @abrasat on GitHub (Nov 9, 2020).

Originally assigned to: @GregorBiswanger on GitHub.

Which version of Electron.NET CLI and API are you using?

  • Latest

Which version of .NET Core and Node.js are you using (if applicable)?

  • Latest

What target are you building for?

  • Windows:

Steps to Reproduce:

  1. Add this entry to appsettings.json
"ConnectionStrings": {
   "SQLiteConnection": "DataSource=mysqlite.db"
}
  1. Add to ConfigureServices() in Startup.cs
services.AddDbContext<ContactsDbContext>(options =>
     options.UseSqlite(Configuration.GetConnectionString("SQLiteConnection")));
  1. Create ContactsDbContext class and pass it to controller constructor
private readonly ContactsDbContext _context;
public ContactsController(ContactsDbContext context)
{       
    _context = context;
}
  1. Prepare HttpGet REST API in controller
[HttpGet]
public async Task<ActionResult<IEnumerable<Contact>>> Get()
{
    var contacts = await _context.Contacts.ToListAsync();
    return contacts;
}
  1. Perform migrations, mysqlite.db file is created in the solution root. Set "Copy Always" option for it. Add manually 2 records into SQLite database.

  2. Prepare menu in Angular code to call HttpGet API.

  3. Start Electron App. Debug with VS2019, attach to application.

  4. Click on menu that triggers HttpGet call. The Get() REST API in ASP .NET Core controller is triggered. No exception is thrown, but the Contacts list is empty (0 records)

The same code works when using it directly in a ASP NET Core application

Originally created by @abrasat on GitHub (Nov 9, 2020). Originally assigned to: @GregorBiswanger on GitHub. <!-- Please search existing issues to avoid creating duplicates. --> Which version of Electron.NET CLI and API are you using? * **Latest** Which version of .NET Core and Node.js are you using (if applicable)? * **Latest** What target are you building for? * **Windows**: <!-- Enter your issue details below this comment. --> <!-- If you want, you can donate to increase issue priority (https://donorbox.org/electron-net) --> Steps to Reproduce: 1. Add this entry to appsettings.json ``` "ConnectionStrings": { "SQLiteConnection": "DataSource=mysqlite.db" } ``` 2. Add to ConfigureServices() in Startup.cs ``` services.AddDbContext<ContactsDbContext>(options => options.UseSqlite(Configuration.GetConnectionString("SQLiteConnection"))); ``` 3. Create ContactsDbContext class and pass it to controller constructor ``` private readonly ContactsDbContext _context; public ContactsController(ContactsDbContext context) { _context = context; } ``` 4. Prepare HttpGet REST API in controller ``` [HttpGet] public async Task<ActionResult<IEnumerable<Contact>>> Get() { var contacts = await _context.Contacts.ToListAsync(); return contacts; } ``` 5. Perform migrations, mysqlite.db file is created in the solution root. Set "Copy Always" option for it. Add manually 2 records into SQLite database. 6. Prepare menu in Angular code to call HttpGet API. 7. Start Electron App. Debug with VS2019, attach to application. 8. Click on menu that triggers HttpGet call. The Get() REST API in ASP .NET Core controller is triggered. No exception is thrown, but the Contacts list is empty (0 records) The same code works when using it directly in a ASP NET Core application
claunia added the bug label 2026-01-29 16:43:32 +00:00
Author
Owner

@abrasat commented on GitHub (Nov 10, 2020):

Update: Yesterday I tested directly from VS 2019 by starting the Electron App with F5.
Today I executed an "electronize build" from the ps console. After that the electron app works correctly, also when started from VS 2019....

@abrasat commented on GitHub (Nov 10, 2020): Update: Yesterday I tested directly from VS 2019 by starting the Electron App with F5. Today I executed an "electronize build" from the ps console. After that the electron app works correctly, also when started from VS 2019....
Author
Owner

@GregorBiswanger commented on GitHub (Mar 28, 2023):

🎉🚀 New Electron.NET version 23.6.1 released 🚀🎉

With native Electron 23 and .NET 6 support. Your problem should be fixed here. If you continue to have the problem, please let us know. Please note the correct updating of your API & CLI. Info in the README. Have fun!

@GregorBiswanger commented on GitHub (Mar 28, 2023): 🎉🚀 New Electron.NET version 23.6.1 released 🚀🎉 With native Electron 23 and .NET 6 support. Your problem should be fixed here. If you continue to have the problem, please let us know. Please note the correct updating of your API & CLI. Info in the README. Have fun!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/Electron.NET#590