MarimerLLC / cslaforum

Discussion forum for CSLA .NET

Home Page:https://cslanet.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Command object MobileList<of T> serialization issues

BlagoCuljak opened this issue · comments

Hi, I am having issues passing a MobileList to my DAL. Basicaly, what I am trying to do is to create a MobileList of the following object:

using System;
using Csla.Core;

namespace FactorOne.Data
    {
                               //in version 4.7 (BinaryFormatter was used) this object was not marked as serializable and did not inherited MobileObject
                               //changes introduced when we upgraded to 5.1
        [Serializable]
        public class LauncherItemDTO : MobileObject
        {
            public int LauncherID { get; set; }
            public int DocumentHeaderID { get; set; }
            public int ItemID { get; set; }
            public decimal LauncherQtyDemand { get; set; }
            public decimal LauncherQtyDemand_m { get; set; }
            public decimal LauncherQtyDemand_kg { get; set; }
            public decimal LauncherSupplyQty { get; set; }
            public decimal LauncherQtyLaunch { get; set; }
            public decimal LauncherQtyLaunch_m { get; set; }
            public decimal LauncherQtyLaunch_kg { get; set; }
            public int LauncherLevel { get; set; }
            public int ItemRoutingID { get; set; }
            public int ItemBOMID { get; set; }
            public int DocumentLineID { get; set; }
            public int LauncherSuperiorItemID { get; set; }
            public int LauncherTopItemID { get; set; }
            public decimal LauncherQtyToDispatch { get; set; }
            public int Parameter1ID { get; set; }
            public int Parameter2ID { get; set; }
            public int Parameter3ID { get; set; }
            public int Parameter4ID { get; set; }
            public int Parameter5ID { get; set; }
            public int PackingWorkcenterID { get; set; }
            public decimal CurrentStock { get; set; }
            public decimal QtyToOrder { get; set; }
        }
    }

It all works fine on the client side. The MobileList<Data.LauncherItemDTO> is created and filled with appropriate data.
In the next step, I am trying to pass that list to my Command object, which in turn should pass it further to my Dal through a DataPortal Execute call.

using Csla;
using System;

namespace FactorOne.Library
{
    [Serializable]
    public class LaunchersBulkInsertCommand : CommandBase<LaunchersBulkInsertCommand>
    {
        public static readonly PropertyInfo<Csla.Core.MobileList<Data.LauncherItemDTO>> launchersToSaveProperty = RegisterProperty<Csla.Core.MobileList<Data.LauncherItemDTO>>(c => c.launchersToSave);
        public Csla.Core.MobileList<Data.LauncherItemDTO> launchersToSave
        {
            get { return ReadProperty(launchersToSaveProperty); }
            private set { LoadProperty(launchersToSaveProperty, value); }
        }

        [Create,RunLocal]
        private void Create(Csla.Core.MobileList<Data.LauncherItemDTO> launchers)
        {
            launchersToSave = launchers;
                                               // MobileList is loaded and the values are assigned neatly to launchersToSaveProperty object,
                                               // for the sake of clarity, list has 4 members at this point and it all looks perfect
        }

        protected override void DataPortal_Execute()
        {
            using (var ctx = FactorOne.Data.DataFactory.GetManager())
            {
                var dal = ctx.GetProvider<FactorOne.Data.ILauncherDal>();
                                                               //in this step -> launchersToSave shows it has 4 objects, but all of their values are set to default (i.e. 0)
                dal.InsertBulkData(launchersToSave);
            }
       }
    }
}

What am I doing wrong here? Is this even possible using a MobileFormatter (CSLA 5.1)? It worked like a charm in Csla 4.7 (BinaryFormatter).
Thanks for the help!

Version and Platform
CSLA version: 5.1
OS: Windows.
Platform:WPF

@BlagoCuljak , is launchersToSave a data transfer object? I have always followed the Project Tracker's way of implementing Data transfer objects.
Based on your code, my guess is, you want to save LauncherstoSave in bulk. If you have business rules to satisfy, I would implement LauncherstoSave as ReadwriteCollection stereotype.
You could then use a datatransfer object similar to ProjectTracker.
just my two cents.

As soon as you use MobileObject you need to use the GetState and SetState methods for serialization:

        public void GetState(Csla.Serialization.Mobile.SerializationInfo info)
        {
            info.AddValue("LauncherID ", LauncherID );
            info.AddValue("DocumentHeaderID ", DocumentHeaderID );
            ...
        }

        public void SetState(Csla.Serialization.Mobile.SerializationInfo info)
        {
            LauncherID = info.GetValue<int>("LauncherID ");
            DocumentHeaderID = info.GetValue<int>("DocumentHeaderID ");
            ...
        }