Article relates to
December 22, 2009
Last modified by
DESCRIPTION Setting default value to a DateTime variable is very useful due to the difference between the DateTime representation in the .NET and the MSSQL. The .NET DateTime value type represents dates and times with values ranging from 12:00:00 midnight, January 1, 0001 through 11:59:59 P.M., December 31, 9999. The DateTime data in the MSSQL is represented from January 1, 1753 through December 31, 9999. When no value is provided for a DateTime field of a persistent object, OpenAccess automatically uses the empty DateTime constructor to set a default value to that field before persisting it on the database server. When a new DateTime variable is created in the .NET environment via the default DateTime constructor it is assigned with the following value "1/1/0001 12:00:00 AM". When trying to push this value to the MSSQL server, an exception will be thrown because of the MSSQL DateTime handling that was mentioned above. SOLUTION Telerik OpenAccess ORM provides a mechanism for setting default value of datetime fields. For instance, a developer wants to store audit information in the database and instead of setting the audit date field in the code he/she would like to do that automatically. Setting datetime field’s default value using the wizard Run the Forward Mapping Wizard from the Telerik -> OpenAccess menu in Visual Studio. Locate and expand the class node. Click on the field node inside the expanded class node. On the right side, under the Field section, you could select the desired setting.
Copyright © 2016, Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks or appropriate markings.