Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xamarin表单上的SQLite网络扩展示例_Sqlite_Xamarin_Xamarin.forms_Sqlite Net_Sqlite Net Extensions - Fatal编程技术网

Xamarin表单上的SQLite网络扩展示例

Xamarin表单上的SQLite网络扩展示例,sqlite,xamarin,xamarin.forms,sqlite-net,sqlite-net-extensions,Sqlite,Xamarin,Xamarin.forms,Sqlite Net,Sqlite Net Extensions,我对在Xamarin表单中使用SQlite网络扩展感兴趣。我正在使用Visual Studio 2013、NuGet的SQlite.Net PCL 2.3.0和一个空白的Hello World Xamarin Forms PLC项目。作为第一步,我试图让Sqlite.NETExtensions站点的示例正常工作。根据Xamarin网站上建议的方法,我正在使用DependencyService获取SQLIteConnection。但是,我的代码甚至不会编译,因为它在SQLiteConnection

我对在Xamarin表单中使用SQlite网络扩展感兴趣。我正在使用Visual Studio 2013、NuGet的SQlite.Net PCL 2.3.0和一个空白的Hello World Xamarin Forms PLC项目。作为第一步,我试图让Sqlite.NETExtensions站点的示例正常工作。根据Xamarin网站上建议的方法,我正在使用DependencyService获取SQLIteConnection。但是,我的代码甚至不会编译,因为它在SQLiteConnection上找不到UpdateWithChildren或GetWithChildren方法。很明显,我的SQLiteConnection对象并没有与示例中的所有内容相同。我是否使用了错误的SQLite.Net PCL库?Xamarin和SQLite网络扩展都建议使用NuGet的PCL版本,这就是我认为我所拥有的

我在Xamarin论坛上也发布了以下内容:

这是我的代码,除了ISQLite类。 数据模型:

using SQLiteNetExtensions.Attributes;
using SQLite.Net.Attributes;


namespace Sample.Models
{
    public class Stock
    {
        [PrimaryKey, AutoIncrement]
        public int Id { get; set; }
        [MaxLength(8)]
        public string Symbol { get; set; }

        [OneToMany]      // One to many relationship with Valuation
        public List<Valuation> Valuations { get; set; }
    }

    public class Valuation
    {
        [PrimaryKey, AutoIncrement]
        public int Id { get; set; }

        [ForeignKey(typeof(Stock))]     // Specify the foreign key
        public int StockId { get; set; }
        public DateTime Time { get; set; }
        public decimal Price { get; set; }

        [ManyToOne]      // Many to one relationship with Stock
        public Stock Stock { get; set; }
    }
}
这是我的数据库助手。现在我只是在构造函数中运行一个测试。我得到的错误是找不到UpdateWithChildren和GetWithChildren方法

using Sample.Models;
using SQLite.Net;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;

namespace Sample.Orm
{
    class DatabaseHelper
    {
        private SQLiteConnection db;

        public DatabaseHelper()
        {
            db = DependencyService.Get<ISQLite>().GetConnection();
            //Create the tables

            db.CreateTable<Stock>();
            db.CreateTable<Valuation>();

            var euro = new Stock()
            {
                Symbol = "€"
            };
            db.Insert(euro);   // Insert the object in the database

            var valuation = new Valuation()
            {
                Price = 15,
                Time = DateTime.Now,
            };
            db.Insert(valuation);   // Insert the object in the database

            // Objects created, let's stablish the relationship
            euro.Valuations = new List<Valuation> { valuation };

            db.UpdateWithChildren(euro);   // Update the changes into the database
            if (valuation.Stock == euro)
            {
                Debug.WriteLine("Inverse relationship already set, yay!");
            }

            // Get the object and the relationships
            var storedValuation = db.GetWithChildren<Valuation>(valuation.Id);
            if (euro.Symbol.Equals(storedValuation.Stock.Symbol))
            {
                Debug.WriteLine("Object and relationships loaded correctly!");
            }
        }
    }
}

来自Xamarin support的Jon Goldberger为我指明了正确的方向。对于将来发现这篇文章的人,简而言之,解决方案是,除非您使用MvvmCross,否则您需要从源代码构建SQLite网络扩展,否则不要使用预编译的dll。一旦您从他们的git服务器中提取,您需要添加SQLiteNetExtensions-PCL.csproj,使用Project->restore packages还原它的包,然后从您的基础项目中引用SQLiteNetExtensions PCL项目。

Xamarin support的Jon Goldberger为我指出了正确的方向。对于将来发现这篇文章的人,简而言之,解决方案是,除非您使用MvvmCross,否则您需要从源代码构建SQLite网络扩展,否则不要使用预编译的dll。一旦您从他们的git服务器中提取,您需要添加SQLiteNetExtensions-PCL.csproj,使用Project->restore packages还原它的包,然后从您的基础项目中引用SQLiteNetExtensions PCL项目。

SQLite Net Extensions现在可以作为MvvmCross和SQLite Net标准PCL风格的NuGet包提供。这应该可以解决这样的问题:库是用一个SQLite Net版本编译的,但用另一个SQLite Net版本执行的,这可能会导致您描述的问题

链接:

对于SQLite Net PCL: 对于MvvmCross SQLite社区插件:
SQLite Net Extensions现在作为用于MvvmCross和SQLite Net的标准PCL风格的NuGet包提供。这应该可以解决这样的问题:库是用一个SQLite Net版本编译的,但用另一个SQLite Net版本执行的,这可能会导致您描述的问题

链接:

对于SQLite Net PCL: 对于MvvmCross SQLite社区插件:
下面是完全限定类名称空间和方法。 刚才补充说:


下面是完全限定类名称空间和方法。 刚才补充说:


我更新到使用Nuget版本。这是正确的答案。我更新到使用Nuget版本。这是正确的答案。
SQLiteNetExtensions.Extensions.ReadOperations.GetAllWithChildren()
SQLiteNetExtensions.Extensions.WriteOperations.UpdateWithChildren()