SQLite Extensions Cascading not working

Alaa81Alaa81 Member ✭✭

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);

Answers

  • Alaa81Alaa81 Member ✭✭
    Any help is much appreciated :#
  • batmacibatmaci DEMember ✭✭✭✭✭
    Wow 4 years back I was in that mess also. Cascading is total mess if you have 3-4 level objects. I cannot really help here but I may suggest to check akavache. This is what I am using and so far works like a charm.
Sign In or Register to comment.