ILog interface class:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.ComponentModel.DataAnnotations; namespace Test1.Models { interface ILog { [Required] [RegularExpression(@"(\s|.){1,50}$", ErrorMessage = "Field cannot contain more than 50 characters")] string Name { get; set; } [Required] [RegularExpression(@"[0-9]*", ErrorMessage = "Field must be an integer")] int TableKey { get; set; } [Required] [RegularExpression(@"(\s|.){1,50}$", ErrorMessage = "Field cannot contain more than 500 characters")] string Value { get; set; } } }
Log LinqToSql class:
using Test1.Models; using System.ComponentModel.DataAnnotations; namespace Log.Model { [MetadataType(typeof(ILog))] partial class Log : ILog { } }Simple enough?For larger models, I suggest creating a ViewModel and handle everything in there...