【发布时间】:2016-10-18 18:00:17
【问题描述】:
我是 Xamarin Forms 和 Xamarin 的新手。我可能误解了架构的工作原理,或者我可能在网上遵循了不同的示例。我正在尝试尽可能多地使用Portable Class Library。
我的 nuget 包是 Xamarin.Forms 和 SQLite.Net-PCL。它们安装在所有设备上,Droid、ios、windows 和 PCL。绝对是最新验证的最高下载量。我正在遵循这些指南
https://developer.xamarin.com/guides/xamarin-forms/working-with/databases/
在 SQLite 接口的 SQLite_Droid 实现上,我无法访问 Xamarin.Forms using 语句或具有接口的语句,这是Native_PCL 项目中的所有代码。
ISQLite.cs
using SQLite.Net;
namespace Native_PCL.DataServices
{
interface ISQLite
{
SQLiteConnection GetConnection();
}
}
DataCalls.cs
using System.Linq;
using SQLite.Net;
using Xamarin.Forms;
using Native_PCL.Data;
namespace Native_PCL.DataServices
{
public class DataCalls
{
static object locker = new object();
SQLiteConnection db;
public DataCalls()
{
db = DependencyService.Get<ISQLite>().GetConnection();
db.CreateTable<UserPreferences>();
db.CreateTable<Orders>();
}
public void SubmitData(Orders order, out string update)
{
lock (locker)
{
if (!db.Table<Orders>().Any(x => x.foodName == order.foodName))
{
db.Insert(order);
update = order.foodName;
}
else { update = order.foodName + " was already in your Order"; }
}
}
}
}
这是Native_PCL.Droid项目中的所有代码
SQLite_Droid.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content; // for some reason all of the System. and Android. are showing white. Usually unused statements are grayed out!
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Native_PCL;
using Native_PCL. ; /// only .Droid is registering
using Xamarin.Forms; //Intellisense does not pick this up
namespace Native_PCL.Droid.DataImplement
{
public class SQLite_Droid : Native_PCL.DataServices.ISQLite /// All white, Doesn't register the ISQLite as an Interface.
{
}
}
我已经重新创建了整个项目。我一定是做错了什么。
【问题讨论】:
标签: c# sqlite xamarin.android