vendredi 18 septembre 2015

Can't find SQLitePlatformIOS in Sqlite.net PCL

I've used nuget package manager to download this package

The example shows:

public class SQLiteFactoryiOS : ISQLiteFactory
{
    public SQLite.Net.SQLiteConnection CreateConnection(string dbName)
    {
        var path = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), dbName);
        return new SQLite.Net.SQLiteConnection(new SQLitePlatformIOS(), path);
    }
}

The issue I am facing is that I can't reference SQLitePlatformIOS. I even found it in the source code, but I'm not able to reach the .Platform namespace, thus I'm unable to create a SQLitePlatformIOS object.

 using SQLite.Net; //.Platform.XamarinIOS <-- Compiler error if I try to reach this

The project I'm using to reference this is a portable class project, because in the references folder I see .NET Portable Subset.

The structure of the project is

iOS MainProject references Example Portable Project Example Portable Project references SQLite.Net-PCL

In the Portable Project I have

References
     .NET Portable Subset
     From Packages
          SQLite.Net
Packages
     SQLite.Net-PCL
Data
     Repositories
           ExampleRepository.cs

My example repository is

using System;
using Example.Data.DTO;
using Example.Models.Properties;

using SQLite.Net;

namespace Example.Data.Repositories
{
    public class ExampleRepository(string dbPath)
    {
        using (var db = new SQLite.Net.SQLiteConnection(new SQLitePlatformIOS() /* Can't reference */, dbPath))
        {
             db.CreateTable<ExampleDTO>();
        }
    }
}

And I call this class from the iOS project.

partial void SaveObject(NSObject sender)
{
    var objectToSave = CreateObjectFromView();
    var dbPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Test.db3");
    var repo = new ExampleRepository(dbPath);
}

Aucun commentaire:

Enregistrer un commentaire