Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

SQLite Extensions Cascading not working

$
0
0

Hi all,
I am having difficulty in getting the List values of 'children' using SQLite Extensions NuGet package in an MVVM structure. I always get all the values of other 'children' from all the other 'parents' even while using the One-To-Many relationships; that meas no cascading effect. Perhaps, I might be doing something wrong. Here's some of the code.

//Models

public class StockGrouping : IEnumerable<Stock>
    {
        [PrimaryKey, AutoIncrement]
        public int Id { get; set; }

    [Column("Description"), NotNull]
    [Indexed]
    public string Description { get; set; }

    [OneToMany(CascadeOperations = CascadeOperation.All)]      // One to many relationship with Stocks
    public List<Stock> Stocks { get; set; }

    public IEnumerator<Stock> GetEnumerator()
    {
        return Stocks.GetEnumerator();
    }

    System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
    {
        return Stocks.GetEnumerator();
    }
}

public class Stock : IEnumerable<Valuation>
{
    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }
    [MaxLength(8)]
    public string Symbol { get; set; }

    [Column("StockGroupingId")]
    [ForeignKey(typeof(StockGrouping))]
    public int StockGroupingId { get; set; }
    [ManyToOne]
    public StockGrouping StockGrouping { get; set; }

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


    public IEnumerator<Valuation> GetEnumerator()
    {
        return Valuations.GetEnumerator();
    }

    System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
    {
        return Valuations.GetEnumerator();
    }

//DataHelper

        public DatabaseHelper()
        {
            db = DependencyService.Get<ISQLite>().GetConnection();
            db.CreateTable<Stock>();
            db.CreateTable<StockGrouping>();
            db.CreateTable<Valuation>();

        }

    public List<Stock> GetAllStocksData(int StockGroupingId)
            {
                return (from data in db.GetAllWithChildren<Stock>() select data).ToList();
            }
    public void InsertStock(Stock stock)
            {
                db.InsertWithChildren(stock);
            }

//Repositories

public List<Stock> GetAllStocksData(int StockGroupingId)
        {
            return _databaseHelper.GetAllStocksData(StockGroupingId);
        }

//IRepositories

List<Stock> GetAllStocksData(int StockGroupingId);

//BaseViewModel

List<Stock> _stockList;
        public List<Stock> StockList
        {
            get => _stockList;
            set
            {
                _stockList = value;
                NotifyPropertyChanged("StockList");
            }
        }

//ViewModel

StockList = _dataRepository.GetAllStocksData(_stock.StockGroupingId);

Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>