Click here to Skip to main content
15,902,112 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm Declaring a Property with DateTimeOffset DataType in EntityFramework like below:
public class ClientSPOC
   {

       [Key]
       [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
       public int ClientSPOCID { get; set; }
       public string CreatedBy { get; set; }

       [DatabaseGenerated(DatabaseGeneratedOption.Computed)]
       [DefaultValue("getutcdate()")]
       public DateTimeOffset CreatedDate { get; set; }

       public string UpdatedBy { get; set; }

       [DatabaseGenerated(DatabaseGeneratedOption.Computed)]
       [DefaultValue("getutcdate()")]
       public DateTimeOffset UpdatedDate { get; set; }

       public bool IsDelete { get; set; }
       public int ManagerContactID { get; set; }

       //Code for Foreign Key for Client Table
       [Required]
       public int ClientID { get; set; }
       //[ForeignKey("ClientID")]
       //public Client clients { get; set; }

       //Code for Foreign Key for ClientContact Table
       [Required]
       public int ClientContactID { get; set; }
       //[ForeignKey("ClientContactID")]
       //public ClientContact clientcontacts { get; set; }
   }



In the above Example Default Precision for CreatedDate and UpdatedDate is 8 , But I want Precision 2 not 8.

How can I change the Precision for DateTimeOffset(2).

What I have tried:

I tried Like this , But its not working Correctly..Please help me to solve my issue
The below Code is written on Dbcontext Class..
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{

    //Specify the DatetimeOffset with Precision 2 for CreatedDate and UpdatedDate in ClientSPOC
    modelBuilder.Entity<ClientSPOC>().Property(p => p.CreatedDate).HasPrecision(2);
    modelBuilder.Entity<ClientSPOC>().Property(p => p.UpdatedDate).HasPrecision(2);

    base.OnModelCreating(modelBuilder);
}
Posted
Comments
Patrice T 28-Dec-17 7:38am    
Give details, a date is a date, there is no precision.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900