Sql-Server-Ce Database saving problem

Answered Sql-Server-Ce Database saving problem

  • Friday, January 11, 2013 1:55 PM
     
      Has Code
    Straight to the problem,
    I have 4 tabels, they are linked like that
    1<--2<--3<--4
    The 4rth one cannot exist without 3rd one etc.
    I named my 3rd table Statistic and the 4rth one Data, Statistic contains avg values made from data. 
    Im responsible for synchro with the cloud.
    Updating ea Data on local is problematic when it comes to thousands of datas so i thought of deleting all the data for the statistic and inserting whole package of data at once when the synchro is completed, wich goes rly fast.

    I delete all the data with   "all data delete"
    private void deleteAlldata(){
    Statistic ss = ActiveStat;
    
    
                var dat = from Data d in LocalDatabase.Datas where d._statisticId == ss.StatisticId select d;
                LocalDatabase.Datas.DeleteAllOnSubmit(dat.ToList());
                LocalDatabase.SubmitChanges();
    }


                

    It goes, no errors.
    Now It want to update Statistic Table. Here I get an Error.

    Error# 
    
    >An attempt was made to remove a relationship between a Car and a Statistic. However, one of the relationship's foreign keys (Statistic._carId) cannot be set to null.



    I'm sure that I'm not doing anything with the Statistic Table.
    I downloaded the data from my local database and checked it.
    Everything was at it should be, Data was updated, it had all required fields, Statistic had everything it should, expect the last thing where it does crash.
    I can't update anything in the statistc table after the "all data delete"

    Defintion of my sync column in Statistic:

    [Column(DbType = "int" ,CanBeNull = true)]
    
           public int Synced
           {
                get { return _synced; }
                set
                {
                        NotifyPropertyChanging("Synced");
                        _synced = value;
                        NotifyPropertyChanged("Synced");
                    
                }
            }



    and the definition of my linking column with the other 2nd one (remeber 1<-2<-3<-4)

    [Column]
    internal int _carId;
    
    [Association(Storage = "_car", ThisKey = "_carId", OtherKey = "CarId", IsForeignKey = >true)]
    
            public Car LinkedCar
            {
                get { return _car.Entity; }
                set
                {
                    NotifyPropertyChanging("LinkedCar");
                    _car.Entity = value;
    
                    if (value != null)
                    {
                        _carId = value.CarId;
                    }
    
                    NotifyPropertyChanging("LinkedCar");
                }
            }



    I'm not sure if it has anything to it but I work on application for windows phone 8 platform

All Replies