Is this data annotation correct for date and time?
-
Hi, I'm creating models for my ASP.NET Core project. I want to use "Code First" approach to create database and tables. Please check these annotations to be correct:
[Required]
[DataType(DataType.Date)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")]
public DateTime creationDate { get; set; }
[Required]
[DataType(DataType.Time)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:HH:mm:ss}")]
public DateTime creationTime { get; set; }And please tell me that what 0 means inside the curly braces.
-
Hi, I'm creating models for my ASP.NET Core project. I want to use "Code First" approach to create database and tables. Please check these annotations to be correct:
[Required]
[DataType(DataType.Date)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")]
public DateTime creationDate { get; set; }
[Required]
[DataType(DataType.Time)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:HH:mm:ss}")]
public DateTime creationTime { get; set; }And please tell me that what 0 means inside the curly braces.
The
DataFormatString
value is a format string to convert a date to a string in the format shown. The zero gives the position of the data parameter (following the format string) when the format is used, like:string theDate = string.Format(DataFormatString, someDateTimeValue);
-
The
DataFormatString
value is a format string to convert a date to a string in the format shown. The zero gives the position of the data parameter (following the format string) when the format is used, like:string theDate = string.Format(DataFormatString, someDateTimeValue);
Is data annotation for the time correct?
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:HH:mm:ss}")]
-
Is data annotation for the time correct?
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:HH:mm:ss}")]
-
I deliberately did not answer that part because I don't know the answer. Does it correspond to the documentation?
No, I did not find any reference for time format. Can I use String type instead?
-
No, I did not find any reference for time format. Can I use String type instead?
-
Hi, I'm creating models for my ASP.NET Core project. I want to use "Code First" approach to create database and tables. Please check these annotations to be correct:
[Required]
[DataType(DataType.Date)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")]
public DateTime creationDate { get; set; }
[Required]
[DataType(DataType.Time)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:HH:mm:ss}")]
public DateTime creationTime { get; set; }And please tell me that what 0 means inside the curly braces.
I get what you want to do here, which is to create models to match your database perhaps, so each table has a matching model. But your over thinking this, and don't need that much detail. Keep it simple and flexible at first, and only add detail when needed. For some reason Microsoft likes to capitalize the first letter, and will nag you later about the first letter being lower case. This is an example model in c# to match a DB table or collection. Your example is a like a model used to present data in the view. Even when presenting data in the view, I would keep that simple as well. You want to craft models as simple as possible, and try to make them as reusable as possible to keep models down in count.
public class PORTFOLIOS
{
// standard BsonId generated by MongoDbpublic string Id { get; set; } public DateTime TimeStamp { get; set; } public string Name { get; set; } public string Description { get; set; } public string CreatedBy { get; set; } public string UpdatedBy { get; set; } public DateTime UpdateDate { get; set; } public string HTML { get; set; } public string AvatarB64 { get; set; } public string AvatarName { get; set; } public string AvatarType { get; set; } public string AvatarUrl { get; set; } public int AvatarX { get; set; } public int AvatarY { get; set; } }
If it ain't broke don't fix it Discover my world at jkirkerx.com