Forum Xamarin.Forms

How to use EntityFrameworkCore.Sqlite with MvvmCross

iooovoltsiooovolts Member ✭✭✭

I was wondering if anyone knows how I could obtain the filepath needed from both Android and iOS so I could pass it into my Context class in order to store the file correctly.

I have been trying to find some sort of example/guide on using ef core sqlite while mvvmcross is present (with xamarin forms) and its proving to be quite the conundrum. The best video I could find of ef core sqlite is (link below). He does an excellent job however, as I am using Mvvmcross we start our application is different ways.

App class in Core project

    namespace TestApp.Core
        public class AppCore : MvxApplication
            public override void Initialize()
                Mvx.IoCProvider.RegisterType<ITestService, TestService>();
                //Mvx.IoCProvider.RegisterType(() => new TestContext("")); from here I don't know what to do
            //The context class by the way is expecting a string filepath to initialise a string field dbPath.



  • GavinGrantGavinGrant GBUniversity ✭✭✭

    Try this.
    Create the DbContext like this :-

    public class TestContext : DbContext {
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) {

    Then register the DbContext as follows :-
    Register the Mvx.IoCProvider.LazyConstructAmndRegisterSingleton<TestContext,TestContext>();

    I have not run this code so it might not be the exact syntax. But it should give you the idea.

  • iooovoltsiooovolts Member ✭✭✭

    @GavinGrant thanks i'll give it a go!

Sign In or Register to comment.