This project has moved and is read-only. For the latest updates, please go here.

SmartDate backing field not generating correctly??

Jun 2, 2011 at 5:24 PM

With my sql server datetime field I am able to do this:

CT.RegisterDate = Convert.ToDateTime(record[6].Trim() + "-" + record[8].Trim() + "-" + record[7].Trim());

Not this:

CT.RegisterDate = record[6].Trim() + "-" + record[8].Trim() + "-" + record[7].Trim();

I get this error when trying the second one.
Cannot implicitly convert type 'string' to 'Csla.SmartDate'. An explicit conversion exists (are you missing a cast?) 

Here is the generated code:

/// <summary>
        /// Maintains metadata about <see cref="RegisterDate"/> property.
        /// </summary>
        private static readonly PropertyInfo<SmartDate> RegisterDateProperty = RegisterProperty<SmartDate>(p => p.RegisterDate, "Register Date");
        /// <summary>
        /// Gets or sets the Register Date.
        /// </summary>
        /// <value>The Register Date.</value>
        public SmartDate RegisterDate
            get { return GetProperty(RegisterDateProperty); }
            set { SetProperty(RegisterDateProperty, value); }

Jun 2, 2011 at 11:01 PM
Edited Jun 2, 2011 at 11:04 PM

Hi farkmischer,

Is it a new project? If it is, under Creation => General Defaults check

  • Use SmartDate instead of DateTime for date properties
  • Use String with TypeConversion to DateTime or SmartDate for date properties

and use creation gesture from Schema Object or Columns panel. These options will generate a string property with a SmartDate backing field. the generated code will look like this

        /// <summary>
        /// Maintains metadata about <see cref="DocDate"/> property.
        /// </summary>
        public static readonly PropertyInfo<SmartDate> DocDateProperty = RegisterProperty<SmartDate>(p => p.DocDate, "Doc Date");
        /// <summary>
        /// Gets or sets the Doc Date.
        /// </summary>
        /// <value>The Doc Date.</value>
        public string DocDate
            get { return GetPropertyConvert<SmartDate, String>(DocDateProperty); }
            set { SetPropertyConvert<SmartDate, String>(DocDateProperty, value); }

You can handle DocDate as a string and Csla will handle the conversion to Smartdate on the background.

If you don't fill like creating your object or property again, just change the Property Type to string and keep the Backing Field Type as SmartDate.