在网上搜索时,很难理解要安装在Xamrin解决方案中的nuget软件包,有几十个软件包,几十种不同的解决方案。
现在,我们的解决方案有两个项目,一个Android项目和一个PCL项目。我们的模型和数据访问定义在PCL中。我们的平台实现是在Android中定义的。
我们需要SQLite、SQLite.Net (用于数据注释和表关系),以及用于* data方法的SQLiteExtentions。
我们被困在旧版本,因为每当我们试图更新任何东西,我们脆弱的神奇方式,我们安装的软件包一起工作,只是崩溃了。我们确实需要升级或者找到一种方法来将SQLCipher添加到这个奇怪的nuget软件包中。
我们目前安装的软件包,其工作原理是:
Android项目
项目(模型定义和数据访问方法)
目前,如果我们将SQLiteExtensions更新为2.0,则会安装许多其他的SQLite nuget包,从而破坏了数据访问代码的脆弱稳定性(在*WithChildren方法上失败的有:
Severity Code Description Project File Line Suppression State
Error CS1929 'SQLiteConnection' does not contain a definition for
'GetWithChildren' and the best extension method overload
'ReadOperations.GetWithChildren<TEntity>(SQLiteConnection, object, bool)'
requires a receiver of type 'SQLiteConnection' 我们还需要合并SQLiteCipher,并且不能使软件包组合来使用我们的解决方案。
我们的Android平台的具体实现:
#region Usings
using OURPCLLib.DataAccess;
using Serilog;
using SQLite.Net;
using SQLite.Net.Interop;
using SQLite.Net.Platform.XamarinAndroid;
using System;
using System.IO;
#endregion Usings
public class AndroidSQLiteDatabase : SQLiteDatabaseAccess
{
protected ISQLitePlatform SQLitePlatform
{
get { return new SQLitePlatformAndroidN(); }
}
protected override SQLiteConnection GetConnection()
{
var conn = new SQLiteConnection(
SQLitePlatform,
"dbpathforus.sqlite",
SQLiteOpenFlags.ReadWrite |
SQLiteOpenFlags.FullMutex |
SQLiteOpenFlags.ProtectionCompleteUnlessOpen |
SQLiteOpenFlags.Create |
SQLiteOpenFlags.SharedCache);
return conn;
}
}PCL中的(简化)基本数据访问类:
#region Usings
using OURPCLLib.DataAccess.Entities;
using SQLite.Net;
using SQLite.Net.Attributes;
using SQLite.Net.Interop;
using SQLiteNetExtensions.Extensions;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Linq.Expressions;
#endregion Usings
public abstract class SQLiteDatabaseAccess
{
protected abstract SQLiteConnection GetConnection();
// Example of one of the many methods accessing the DB using SQLite.Net
public bool Any<TEntity>(Expression<Func<TEntity, bool>> expression)
where TEntity : class, IBaseEntity, new()
{
using (var currentConnection = this.GetConnection())
{
return currentConnection.Table<TEntity>().Where(expression).FirstOrDefault() != null;
}
}
// Example of one of the methods accessing the DB using SQLiteExtentions
public TEntity GetWithChildren<TEntity>(int id, bool recursive = false)
where TEntity : class, IBaseEntity, new()
{
using (var currentConnection = this.GetConnection())
{
return currentConnection.GetWithChildren<TEntity>(id, recursive);
}
}
}任何人都可以帮助我们如何在像我们这样的项目中使用SQLite和SQLIte.net、SQLiteExtentions和SQLIte密码?( pcl中的数据访问和android项目中的连接实现?)
发布于 2018-06-27 11:43:56
对于任何想知道的人,我只通过安装SQLiteNetExtensions并让它自己获得它的SQLite依赖来解决这个问题,它的代码影响很小,功能损失也不多。
https://stackoverflow.com/questions/50841932
复制相似问题