2

Xamarin Forms에서 SQlite-Net Extensions (https://bitbucket.org/twincoders/sqlite-net-extensions)를 사용하는 데 중점을 둡니다. 저는 Visual Studio 2013, NuGet의 SQlite.Net PCL 2.3.0 및 빈 Hello World Xamarin Forms PLC 프로젝트를 사용하고 있습니다. 첫 번째 단계로서 저는 Sqlite.Net 확장 사이트에서 예제를 얻으려고합니다. Xamarin 웹 사이트에서 제안 된 방법에 따라 SQLIteConnection을 얻기 위해 DependencyService를 사용하고 있습니다. 그러나 SQLiteConnection에서 UpdateWithChildren 메서드 나 GetWithChildren 메서드를 찾을 수 없기 때문에 코드가 컴파일되지 않습니다. 내 SQLiteConnection 객체가 예제와 같은 것을 가지고 있지 않다는 것을 알 수 있습니다. SQLite.Net PCL에 잘못된 라이브러리를 사용하고 있습니까? 여기 http://forums.xamarin.com/discussion/20117/sqlite-net-extensions-and-sqliteconnection#latestXamarin Forms의 SQLite-Net Extensions 예제

내입니다 : 두 자 마린과 SQLite는 네트 확장 내가이뿐만 아니라 여기에 자 마린 포럼에 게시 한 나는 내가 가지고있는 생각이다 NuGet,에서 PCL 버전 ...

를 사용하여 제안 코드 (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; } 
    } 
} 

그리고 내 DatabaseHelper입니다. 지금은 생성자에서 테스트를하고 있습니다. 내가 얻은 오류는 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!"); 
      } 
     } 
    } 
} 

답변

3

SQLite-Net Extensions는 이제 SQLite-Net의 MvvmCross 및 표준 PCL 버전을위한 NuGet 패키지로 사용할 수 있습니다. 이렇게하면 라이브러리가 하나의 SQLite-Net 버전으로 컴파일되었지만 다른 버전과 함께 실행되어 설명하는 문제가 발생할 수있는 문제가 해결됩니다.

링크 : SQLite는-인터넷 PCL 들어

+0

. 이것은 바로 지금 대답입니다. – thedigitalsean

0

Xamarin 지원의 Jon Goldberger가 올바른 방향으로 나를 가리켰습니다. 앞으로이 게시물을 찾는 사람들은 간단히 말해 MvvmCross를 사용하지 않으면 소스에서 SQLite-Net Extensions를 빌드해야하며 미리 컴파일 된 dll은 사용하지 마십시오. 당신이 그들의 자식 서버에서 끌어 후에는 SQLiteNetExtensions-PCL.csproj를 추가 그것은 프로젝트 - 함께 패키지의 복원> 패키지를 복원 한 다음 기본 프로젝트에서 SQLiteNetExtensions-PCL 프로젝트를 참조 할 필요가있다.

0

완전 자격 클래스 (네임 스페이스와 방법)입니다.
은 그냥 추가 : 나는 Nuget 버전을 사용하여 업데이트

SQL Lite Extensions

SQLiteNetExtensions.Extensions.ReadOperations.GetAllWithChildren() 
SQLiteNetExtensions.Extensions.WriteOperations.UpdateWithChildren()