简体   繁体   中英

Is it possible to implement business layer validation to the Linq2Sql classes

I am aware of the business layer validation for the model classes in general n-layered architectures model classes, by using validation attributes. Now, I just i want to know if its applicable to Linq2Sql classes, as if I manually add some attributes to the class or its members, then on next addition or deletion in Dbml file, it will rewrite the designer classes, erasing my changes made.

Please help me...

Any idea , sample code or site references are highly appreciated.

You can write a partial class and annotate that

using System.ComponentModel.DataAnnotations;  
namespace MvcDA {
    [MetadataType(typeof(ProductMD))]
    public partial class Product {
        public class ProductMD {
            [StringLength(50),Required]
            public object Name { get; set; }
            [StringLength(15)]
            public object Color { get; set; }
            [Range(0, 9999)]
            public object Weight { get; set; }
          //  public object NoSuchProperty { get; set; }
        }
    }
}

Validate Model Data Using DataAnnotations Attributes

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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