How to add migration to blazor hybrid MAUI?

sblb 1,231 Reputation points
2024-09-29T13:32:04.1433333+00:00

Hi, I use blazor hybrid to do native app in windows platform. I tried to implement migration to connect the local database. Unfortunately is not possible. I don't want to use sqlite. I would like to know if I have to add class library to add migration and applicationdbcontext. Do you have some advise to create the local database? Thanks in advance

Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,596 questions
0 comments No comments
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 66,461 Reputation points
    2024-09-29T16:41:51.4933333+00:00

    Currently a hybrid blazor app is hosted by the browser sandbox similar to WASM. This limits the what code can be executed. The only supported database is sqllite or the browser’s builtin database via jsinterop.

    because the hosting Maui app has access to the hosting webview, you can use messaging for blazor code to call Maui code. So you could define a message api for blazor code to call Maui code to perform database access. Though this would only make sense with a Maui windows desktop app. See the weakmessenger class. Google for blazor examples.

    https://learn.microsoft.com/en-us/dotnet/api/microsoft.toolkit.mvvm.messaging.weakreferencemessenger?view=win-comm-toolkit-dotnet-7.1

    so in short you will create a database api with migrations in the Maui code, not blazor. You will then use messaging for the blazor code to call the Maui code.

    note: as Maui Blazor hybrid goal is to create mobile applications, not windows desktop, database access is typically local SQLite or calling a webapi.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.