The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

Problem saving

Last post 08-08-2008, 4:29 PM by fradique. 2 replies.
Sort Posts: Previous Next
  •  08-08-2008, 1:20 PM 10628

    Problem saving

    This is my first time writing you, first of all this is a great product, im facinated with EntitySpaces.
     
    EntitySpaces Version # 2008.1.0623.0
    MyGeneration Version # 1.2.0.7
    Database: MSSQL
     
    I need a calculated column, i added it like this:
     
    Code:
    1    if (this.Table != null)
    2                {
    3                    if (!Table.Columns.Contains("Minutos"))
    4                        Table.Columns.Add("Minutos", typeof(System.Decimal));
    5    
    6                    TimeSpan dif;
    7                    foreach (CcOrden orden in this)
    8                    {
    9                        if (orden.FecEntregaT.HasValue)
    10                           dif = orden.FecEntregaT.Value - orden.FechaIngreso.Value;
    11                       else
    12                           dif = DateTime.Now - orden.FechaIngreso.Value;
    13   
    14                       orden.SetColumn("Minutos", dif.TotalMinutes);
    15                   }
    16               }
    
     
     
    So, when i try to Save(), it throws me this error:
     
    Code:
    System.NullReferenceException was unhandled
      Message="Object reference not set to an instance of an object."
      Source="EntitySpaces.SqlClientProvider"
      StackTrace:
           at EntitySpaces.SqlClientProvider.Shared.BuildDynamicUpdateCommand(esDataRequest request, List`1 modifiedColumns)
           at EntitySpaces.SqlClientProvider.DataProvider.SaveDynamic(esDataRequest request)
           at EntitySpaces.SqlClientProvider.DataProvider.EntitySpaces.Interfaces.IDataProvider.esSaveDataTable(esDataRequest request)
           at EntitySpaces.Interfaces.esDataProvider.esSaveDataTable(esDataRequest request, esProviderSignature sig)
           at EntitySpaces.Core.esEntityCollection.SaveToProviderInsertsUpdates(esSqlAccessType sqlAccessType)
           at EntitySpaces.Core.esEntityCollection.SaveToProvider(esSqlAccessType sqlAccessType)
           at EntitySpaces.Core.esEntityCollection.Save(esSqlAccessType sqlAccessType)
           at EntitySpaces.Core.esEntityCollection.Save()
           at MayorSys.CcOrdenCollection.Grabar() in C:\Datos\Sistemas\MayorSysCompleto\DatosMayorSys\CallCenter\Custom\CcOrdenCollection.cs:line 55
           at MayorSys.CallCenter.OrdenesAnteriores.simpleButton2_Click_1(Object sender, EventArgs e) in C:\Datos\Sistemas\MayorSysCompleto\MayorSysWin\CallCenter\OrdenesAnteriores.cs:line 93
           at System.Windows.Forms.Control.OnClick(EventArgs e)
           at DevExpress.XtraEditors.BaseButton.OnClick(EventArgs e)
           at DevExpress.XtraEditors.BaseButton.OnMouseUp(MouseEventArgs e)
           at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
           at System.Windows.Forms.Control.WndProc(Message& m)
           at DevExpress.Utils.Controls.ControlBase.WndProc(Message& m)
           at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
           at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
           at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
           at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
           at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
           at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
           at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
           at System.Windows.Forms.Application.Run(Form mainForm)
           at MayorSys.Program.Main() in C:\Datos\Sistemas\MayorSysCompleto\MayorSysWin\Program.cs:line 20
           at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
           at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
           at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
           at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
           at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
           at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
           at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()

    I tried removing the agregated column first:
     
    Code:
    1    if (this.Table != null)
    2                {
    3                    if (Table.Columns.Contains("Minutos"))
    4                        Table.Columns.Remove("Minutos");
    5                    
    6                    this.Save();
    7                }

    i noticed that if i comment: 
    orden.SetColumn("Minutos", dif.TotalMinutes); 
    It works fine, but that was the porpouse of adding the column in the first place,
    im stuck>

    Fradique Lee
  •  08-08-2008, 3:00 PM 10630 in reply to 10628

    Re: Problem saving

    Have you seen this FAQ on Extended Properties? I think it presents a better alternative than trying to manipulate the low level table. "Minutos" would be like "FakeColumn" in the FAQ. You could just loop through and set the "Minutos" property for each entity in the collection to the calculated value. Extended Properties are not saved, and should eliminate that problem.
    David Neal Parsons
    www.entityspaces.net
  •  08-08-2008, 4:29 PM 10632 in reply to 10630

    Re: Problem saving

    Thats works perfectly, thanxs.
    Fradique Lee
View as RSS news feed in XML