简体   繁体   English

转换由EF6创建的Domain类中的日期

[英]Convert date in Domain class that is created by EF6

I create a model using EF6 ,one of my entities as you can see here : 我使用EF6创建了一个模型,您可以在这里看到我的一个实体:

public partial class Comment
    {
        public Comment()
        {
            this.Points = new HashSet<Point>();
        }

        public int Id { get; set; }
        public int IdeaId { get; set; }
        public System.DateTime Date { get; set; }
        public string JurorId { get; set; }
        public string CommectDesc { get; set; }
        public string Point { get; set; }

        public virtual Idea Idea { get; set; }
        public virtual ICollection<Point> Points { get; set; }
    }

Can i convert date column using get{} in this class?I mean i need to converted my date ?because i save the date using datetime.now but when i want to show the date to user i have to convert it to persian date. 我可以在此类中使用get {}转换日期列吗?我的意思是我需要转换日期?因为我使用datetime.now保存了日期,但是当我想向用户显示日期时,我不得不将其转换为波斯日期。

it's better to create new propery and decorate it with [System.ComponentModel.DataAnnotations.Schema.NotMapped] Attribute, Like this 最好创建新属性并用[System.ComponentModel.DataAnnotations.Schema.NotMapped]属性装饰它,像这样

public DateTime Date { get; set; }


[System.ComponentModel.DataAnnotations.Schema.NotMapped]
public DateTime PersianDate
    {
        get
        {
                var value  = ConvertToHijri(Date);

                return (value);
        }
    }

not you have extra field that not mapped to your database, when you want to show datetime in hijri format, you can use PersianDate property instead of Date Property 不是,您有未映射到数据库的额外字段,当您要以hijri格式显示日期时间时,可以使用PersianDate属性代替Date属性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM