哪种方法更好地定义数据注释(视图模型或实体)? [关闭]

2024-02-05

在实体或视图模型中定义数据注释的更好方法?

我有同一实体的实体和视图模型,并使用实体框架的数据注释覆盖该类。 问题是我可以添加它们而无需创建单独的模型,但是我担心哪种方法更好?

先感谢您。

Entity

[Table("BatchInfo")]
    public partial class BatchInfo
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int BatchInfoId { get; set; }
        public string TRANCODE { get; set; }
        public string BatchId  { get; set; }
        public bool AMTFLAG { get; set; }
        public int POS { get; set; }

    }

查看模型

 [NotMapped]
    public class BatchInfoViewModel:BatchInfo
    {
        [Required(ErrorMessage = "Transaction Code is required")]
        [Remote("CheckTranCode", "BatchInfo",AdditionalFields = "BatchInfoId", ErrorMessage = "Transaction Code Already Exists!")]
        [RegularExpression("[A-Za-z0-9^]*", ErrorMessage = "Invalid Transaction Code")]
        [StringLength(3, ErrorMessage = "Transaction Code Should Not be More than 3 Characters")]
        public new string TRANCODE { get; set; }
        [Required(ErrorMessage = "Batch Code is required")]
        [RegularExpression("[A-Za-z0-9^]*", ErrorMessage = "Invalid Batch Code")]
        [StringLength(5, ErrorMessage = "Transaction Code Should Not be More than 5 Characters")]
        public new  string BatchId { get; set; }
        [Required(ErrorMessage = "Position is required")]
        [RegularExpression("^[0-9]*$", ErrorMessage = "Only Number is allowed")]
        [Range(0, int.MaxValue, ErrorMessage = "Invalid Position")]
        public new  int? POS { get; set; }
}

None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

哪种方法更好地定义数据注释(视图模型或实体)? [关闭] 的相关文章

随机推荐