TimeSpan always zero?

3 posts, 0 answers
  1. Bernd
    Bernd avatar
    53 posts
    Member since:
    Feb 2013

    Posted 16 Jun Link to this post

    Hello all.

    I have a TimeSpan property. This is being mapped on SQL-Server to a Datetime column. On retrieval I always get a zero time span

    My persisent class:

    001.#pragma warning disable 1591
    002.//------------------------------------------------------------------------------
    003.// <auto-generated>
    004.//     Dieser Code wurde von einem Tool generiert.
    005.//     Wenn der Code neu generiert wird, gehen alle Änderungen an dieser Datei verloren
    006.// </auto-generated>
    007.//------------------------------------------------------------------------------
    008.using idee5.Dispatcher.Model.Constants;
    009.using System;
    010.using System.Collections.Generic;
    011.using System.ComponentModel.DataAnnotations;
    012.using System.Linq;
    013.using System.Text;
    014. 
    015.namespace idee5.Dispatcher.Model.DAL {
    016.    public partial class Operation : IMasterSystemId {
    017.        [Required(),Key()]
    018.        public virtual int Id {
    019.            get;
    020.            set;
    021.        }
    022. 
    023.        [Required]
    024.        public virtual uint SequenceNumber {
    025.            get;
    026.            set;
    027.        }
    028. 
    029.        /// <summary>
    030.        /// Taktzeit
    031.        /// </summary>
    032.        public virtual float CycleTime {
    033.            get;
    034.            set;
    035.        }
    036. 
    037.        public virtual OperationProcessingStates ProcessingStatus {
    038.            get;
    039.            set;
    040.        }
    041. 
    042.        public virtual float QuantityPerCycle {
    043.            get;
    044.            set;
    045.        }
    046. 
    047.        [Required()]
    048.        public virtual string Description {
    049.            get;
    050.            set;
    051.        }
    052. 
    053.        /// <summary>
    054.        /// Produzierte Menge der Komponente
    055.        /// </summary>
    056.        public virtual float QuantityConfirmed {
    057.            get;
    058.            set;
    059.        }
    060. 
    061.        /// <summary>
    062.        /// Ausschussmenge der Komponente
    063.        /// </summary>
    064.        public virtual float QuantityDefective {
    065.            get;
    066.            set;
    067.        }
    068. 
    069.        /// <summary>
    070.        /// Menge der Komponenten mit verminderter Qualität.
    071.        /// </summary>
    072.        public virtual float QuantityLessQuality {
    073.            get;
    074.            set;
    075.        }
    076. 
    077.        /// <summary>
    078.        /// Rüstzeit
    079.        /// </summary>
    080.        public virtual TimeSpan SetupTime {
    081.            get;
    082.            set;
    083.        }
    084. 
    085.        /// <summary>
    086.        /// Stückzeit
    087.        /// </summary>
    088.        public virtual TimeSpan TimePerUnit {
    089.            get;
    090.            set;
    091.        }
    092. 
    093.        /// <summary>
    094.        /// Geplanter Start des Arbeitsgangs
    095.        /// </summary>
    096.        public virtual DateTime? StartScheduled {
    097.            get;
    098.            set;
    099.        }
    100. 
    101.        /// <summary>
    102.        /// Geplantes Ende des Arbeitsgang
    103.        /// </summary>
    104.        public virtual DateTime? EndScheduled {
    105.            get;
    106.            set;
    107.        }
    108. 
    109.        /// <summary>
    110.        /// Tatsächlicher Start des Arbeitsgang
    111.        /// </summary>
    112.        public virtual DateTime? StartActual {
    113.            get;
    114.            set;
    115.        }
    116. 
    117.        /// <summary>
    118.        /// Tatsächliches Ende des Arbeitsgang
    119.        /// </summary>
    120.        public virtual DateTime? EndActual {
    121.            get;
    122.            set;
    123.        }
    124. 
    125.        public virtual int WorkOrderId {
    126.            get;
    127.            set;
    128.        }
    129. 
    130.        public virtual int? CycleTimeUoM {
    131.            get;
    132.            set;
    133.        }
    134. 
    135.        public virtual int? WorkplaceId {
    136.            get;
    137.            set;
    138.        }
    139. 
    140.        public virtual int? OperatingResourceId {
    141.            get;
    142.            set;
    143.        }
    144. 
    145.        /// <summary>
    146.        /// Berechneter Start des Arbeitsgang
    147.        /// </summary>
    148.        public virtual DateTime? StartCalculated {
    149.            get;
    150.            set;
    151.        }
    152. 
    153.        /// <summary>
    154.        /// Highest rank means highest efficiency
    155.        /// </summary>
    156.        [Required]
    157.        public virtual char EfficiencyRank {
    158.            get;
    159.            set;
    160.        }
    161. 
    162.        /// <summary>
    163.        /// Liefezeit nach Arbeitsgang
    164.        /// </summary>
    165.        public virtual TimeSpan WaitTimeAfter {
    166.            get;
    167.            set;
    168.        }
    169. 
    170.        // Implementation of IMasterSystemId
    171.        /// <summary>
    172.        /// Master systems hierarchical identification. E.g. Company and/orPlant
    173.        /// </summary>
    174.        public virtual string MasterSystemHierarchy { get;set; }
    175. 
    176.        /// <summary>
    177.        /// Master systems unique  identification within the hierarchy.
    178.        /// </summary>
    179.        public virtual string MasterSystemId { get;set; }
    180. 
    181.        // association properties
    182.        private IList<MaterialComponent> materialComponents = new List<MaterialComponent>();
    183.        public virtual IList<MaterialComponent> MaterialComponents {
    184.            get { return this.materialComponents;}
    185.        }
    186. 
    187.        private IList<Transaction> transactions = new List<Transaction>();
    188.        public virtual IList<Transaction> Transactions {
    189.            get { return this.transactions;}
    190.        }
    191. 
    192.        private IList<MessageEvent> messageEvents = new List<MessageEvent>();
    193.        public virtual IList<MessageEvent> MessageEvents {
    194.            get { return this.messageEvents;}
    195.        }
    196. 
    197.        private IList<CalendarEvent> calendarEvents = new List<CalendarEvent>();
    198.        public virtual IList<CalendarEvent> CalendarEvents {
    199.            get { return this.calendarEvents;}
    200.        }
    201. 
    202.        public virtual Item OperatingResource {
    203.            get;
    204.            set;
    205.        }
    206. 
    207.        public virtual UnitOfMeasure CycleUoM {
    208.            get;
    209.            set;
    210.        }
    211. 
    212.        public virtual Workplace Workplace {
    213.            get;
    214.            set;
    215.        }
    216. 
    217.        public virtual WorkOrder WorkOrder {
    218.            get;
    219.            set;
    220.        }
    221. 
    222.    }
    223.}
    224.#pragma warning restore 1591

    Not being able to upload a screenshot I just can give the value stored in the database: "1907-08-05 00:00:00.000".

    The value makes no sense, but yet it is more than zero.

    How can I make this work?

    Kind regards

    Bernd

  2. Thomas
    Admin
    Thomas avatar
    590 posts

    Posted 17 Jun Link to this post

    Hi Bernd,

    looks like there is a mapping glitch, and the wrong type converter is used internally. Using a DateTime property internally (private prop is sufficient) and mapping that to the column, but exposing the TimeOfDay part only through a new non-persistent property should be sufficient to get you out of this (or using the full DateTime property directly). Also, you could consider using a time column when you are interested in the TimeSpan only.
    I personally would recommend using either a TIME column for this property or using a DateTime property for this column, so that CLR and SQL types match up. Keep in mind, that there will be issues storing dates before 1753 in MSSQL.

    Regards,
    Thomas
    Telerik
     
    Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
  3. DevCraft banner
  4. Bernd
    Bernd avatar
    53 posts
    Member since:
    Feb 2013

    Posted 21 Jun in reply to Thomas Link to this post

    Hello Thomas.

    Thanks for pointing me in the right direction.

    I chose the DateTime property and convert it in my business logic. Not very sexy, but seems to be neccessary as long there is this bug in Data Access.

    Hopefully Telerik corrects this in a future version. Would be nice to have a more natural way of handling time spans.

    Regards

    Bernd

Back to Top