2015-09-03 1 views
-1

J'utilise l'extension net SQLite pour créer un à plusieurs rapports pour 2 tables qui me sers il y a des tables dans mon code C#-je suivre tutoriel site officiel https://bitbucket.org/twincoders/sqlite-net-extensionsnette extension SQLite relation un à plusieurs Windows Phone

[Table("Stock")] 
public class Stock 
{ 
    [PrimaryKey, AutoIncrement] 
    public int Id { get; set; } 
    [MaxLength(8)] 
    public string Symbol { get; set; } 

    [OneToMany(CascadeOperations = CascadeOperation.All)]  // One to many relationship with Valuation 
    public List<Valuation> Valuations { get; set; } 
} 
[Table("Valuation")] 
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; } 
} 

Voici mon code pour créer Stockobject et insérez-le à db

var valuation = new List<Valuation>(); 
     valuation.Add(new Valuation { Price = 1 }); 

     var stock = new Stock(); 
     stock.Valuations = valuation; 

     db.InsertWithChildren(stock); 

mais quand je déboguer le code et lu les données de stock de db il me montre nulle pour la liste d'évaluation ce qui est le problème ici?

That'is comment il me montre à

enter image description here

Répondre

0

Vous devez utiliser db.GetWithChildren<Stock>() au lieu de db.Table<Stock>().

Exemple de twincoders:

// Get the object and the relationships 
var storedValuation = db.GetWithChildren<Valuation>(valuation.Id);