This project is read-only.

Collection.AddItem()

Apr 15, 2010 at 2:29 PM

Hi,

If I do this

City newCity = DataStore.ObservableCityCollection.Single<City>(x => x.Name == "Swansea");
DataStore.MainAppSubDomain.GetCollection<CityCollection>().AddItem(newCity);

 I get : Exception - This row already belongs to another table.

If I Do this

City newCity = (City)DataStore.ObservableCityCollection.Single<City>(x => x.Name == "Swansea").Clone();
DataStore.MainAppSubDomain.GetCollection<CityCollection>().AddItem(newCity);

I get : Execption - The current item must be parented.

If I do this

    class Utility
    {
        public static T DeepCopy<T>(T obj)
        {
            object result = null;

            using (var ms = new MemoryStream())
            {
                var formatter = new BinaryFormatter();
                formatter.Serialize(ms, obj);
                ms.Position = 0;

                result = (T)formatter.Deserialize(ms);
                ms.Close();
            }

            return (T)result;
        }
    }

City newCity = DataStore.ObservableCityCollection.Single<City>(x => x.Name == "Swansea");
City cloneCity = Utility.DeepCopy<City>(newCity);
DataStore.MainAppSubDomain.GetCollection<CityCollection>().AddItem(cloneCity);

I get : Type 'Widgetsphere.Core.DataAccess.BusinessObjectPersistableBase' in Assembly 'Widgetsphere.Core,
         Version=3.6.0.150, Culture=neutral, PublicKeyToken=5cb8d3744e1198c9' is not marked as serializable.

Please help if you have time, I've been on this for two days.

Thank you, Rob

 

Apr 16, 2010 at 12:42 AM

SOLVED :

DataStore and MainAppSubDomain and all the collections I had declared as static.  Reason behind it was to share the data across classes (single user app).  I removed all the statics and made it an instance class, including all its members.  Then instanciated the class where it could be seen and all the problems disappeared. 

Sorry if I wasted any of your time.

Thanks

Rob