且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

扩展的LINQ to SQL生成的类

更新时间:2022-05-27 01:09:37

我知道你已经接受了答案,但我认为这可能是更好的使用设置此部分类。只要您设置了部分类在同一个命名空间同名的,一切都将得到自动设置。下面是我如何设置这在我的一个项目为例:

I know that you already accepted an answer for this but I think it may be better to set this up using partial classes. As long as you set up the partial class in the same namespace with the same name, everything will get set up automatically. Here is an example of how I set this up in one of my projects:

namespace OperationsMetrics
{
[MetadataType(typeof(ClientStatMD))]
public partial class client_wkly_stat : IValidatableObject
{
    public class ClientStatMD
    {
        [Required(ErrorMessage = "Client selection is required")]
        public virtual int client_id { get; set; }
        [Required(ErrorMessage = "SLAs met is required")]
        public virtual int wkly_sla_met { get; set; }
        [Required(ErrorMessage = "Total SLAs possible is required")]
        public virtual int wkly_sla_req { get; set; }
        [Required(ErrorMessage = "Number of input files is received")]
        public virtual int num_inp_files_rec { get; set; }
        [Required]
        public string client_name { get; set; } 

    }

    public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
    {
        if (wkly_sla_met > wkly_sla_req)
        {
            yield return new ValidationResult("SLAs met cannot be greater that SLAs possible");
        }


    }
    public string client_name { get; set; } //this isn't a part of the actual db object but can still be accessed in the Validate method
}

}

您可以设置部分类为 IValidatableObject 它实现了自己的验证方法。你可以对确认支票==在你的验证方法,密码

You can set up the Partial Class as an IValidatableObject which implements its own Validate method. You can have a check for Confirm==Password in your Validate method.

您可以得到一些这方面的更多信息 Pluralsight视频

You can get some more information in this Pluralsight Video