efcore icon indicating copy to clipboard operation
efcore copied to clipboard

EF Core does not work for IOS when using SQLite

Open ltemimi opened this issue 2 years ago • 6 comments

Dot net MAUI Blazor app:

IOS still needs extra work to work with SQL lite the follwoing needs adding: In the project file add:

	PackageReference Include="sqlite-net-pcl" Version="1.8.116" 
	PackageReference Include="SQLitePCLRaw.core" Version="2.1.0-pre20220207221914" 
	PackageReference Include="SQLitePCLRaw.bundle_green" Version="2.1.0-pre20220207221914" 
	PackageReference Include="SQLitePCLRaw.provider.dynamic_cdecl" Version="2.1.0-pre20220207221914" 
	PackageReference Include="SQLitePCLRaw.provider.sqlite3" Version="2.1.0-pre20220207221914" 

And add the following line of code in app delegate raw.SetProvider(new SQLite3Provider_sqlite3());

 public class AppDelegate : MauiUIApplicationDelegate
    {
        protected override MauiApp CreateMauiApp()
        {
            raw.SetProvider(new SQLite3Provider_sqlite3());
            return MauiProgram.CreateMauiApp();
        }
    }

This issues with the IOS platform has been going on for a long time and I am a bit sad that the GA release is worst than preview 13. Android and windows platforms work well

ltemimi avatar May 27 '22 17:05 ltemimi

/cc @bricelam

ajcvickers avatar May 31 '22 19:05 ajcvickers

@ltemimi Are you using either EF Core or Microsoft.Data.Sqlite in your project? All I see is sqlite-net-pcl and the underlying SQLitePCLRaw libraries. AFAIK, SQLite-net doesn't automatically initialize bundles for you. So yes, you'll need to call SQLitePCL.raw.SetProvider.

bricelam avatar May 31 '22 23:05 bricelam

I had understood SQLitePCLRaw so that *.sqlite3 packages is for SQLite versions compiled by yourself or downloaded from sqlite.org 🙂. This scenario is not allowed on iOS, right? Instead, only the OS built-in version of SQLite can be used on iOS. I guess this requires using packages SQLitePCLRaw.provider.sqlite3.ios_unified, SQLitePCLRaw.lib.e_sqlite3.ios_unified.static, and SQLitePCLRaw.core.

But maybe I'm wrong, since I haven't used SQLite myself with iOS yet 🤷‍♂️

SommerEngineering avatar Jun 01 '22 06:06 SommerEngineering

I am using EF core as a back end to a Blazor server using DB context pointing to an SQLite Db. When I use the Blazor app with dot net MAUI it works out of the box for Windows and Android. But not IOS I was not expecting to do extra work for IOS In my view it seems EF core handle windows and android platform correctly but perhaps the files it uses for IOS are outdated I am not sure.

ltemimi avatar Jun 01 '22 11:06 ltemimi

Seems as though a similar problem is occurring with net6.0-maccatalyst https://github.com/unoplatform/uno/discussions/9113 . Should I make a separate ticket?

bstrother1 avatar Jun 23 '22 15:06 bstrother1

Hi

Hang on Please the added to 7.0.0 milestone, I have just convinced a customer to go with dot net MAUI GA release, I am sorry is there a way of accelerating a bit I will be very grateful. It is inconvenient enough to use Visual Studio Preview which makes the GA MAUI release a bit premature.

Please help my customer needs it now

ltemimi avatar Jun 23 '22 19:06 ltemimi

On Xamarin.Forms, I just used the following and it worked:

            SQLitePCL.Batteries_V2.Init();
            SQLitePCL.raw.sqlite3_config(SQLitePCL.raw.SQLITE_CONFIG_SERIALIZED);

After upgrading to MAUI, I tried leaving it off. Seemed to work in the simulator, but starting to experience problems now. Wondering what the optimal configuration is for the SQLite provider on iOS

symbiogenesis avatar Dec 17 '22 06:12 symbiogenesis

Any updates ? same problem in maui and ios

AHComp avatar Jul 26 '23 14:07 AHComp