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!");
}
}
}
}
. 이것은 바로 지금 대답입니다. – thedigitalsean