i have a Problem with my SQLite-Database. I use the SQLite.Net and SQLiteNetExtensions PCL NuGets and followed this excample: Link
I have a connection and it insert a stock but not the valuation list.
My copy paste code:
var valuation1 = new Valuation
{
Price = 15,
Time = DateTime.Now,
};
var valuation2= new Valuation
{
Price = 22,
Time = DateTime.Now,
};
var euro = new Stock
{
Symbol = "€",
Valuations = new List<Valuation> { valuation1, valuation2 }
};
connection.CreateTable<Stock>();
connection.CreateTable<Valuation>();
connection.InsertWithChildren(euro);
var stockList = c.GetAllWithChildren<Stock>();
In Stocklist is a Stock but in Stock is no Valuation :(
usings:
using System; using System.Collections.Generic;
using System.Linq;
using SQLiteNetExtensions.Extensions;
using TestSQLite.Models;
Models:
using SQLite.Net.Attributes;
using SQLiteNetExtensions.Attributes;
using System;
using System.Collections.Generic;
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; }
}
using SQLite.Net.Attributes;
using SQLiteNetExtensions.Attributes;
using System;
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; }
}
Any ideas or suggestions what i could do to make it work?
Aucun commentaire:
Enregistrer un commentaire