관리 메뉴

심재운 블로그

ASP.NET 3.5 Dynamic Data 에서 사용할 있는 Attribute 들.. 본문

닷넷관련/ASP.NET WEBFORM

ASP.NET 3.5 Dynamic Data 에서 사용할 있는 Attribute 들..

재우니 2009. 9. 15. 01:46

 using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;


namespace Domain
{
    [MetadataType(typeof(ContactMetadata))]
    [DisplayColumn("LastName", "LastName")]
    public partial class Contact
    {
        private string _newEmail;


        partial void OnEmailChanging(string value)
        {
            this._newEmail = value;
        }


        partial void OnValidate(System.Data.Linq.ChangeAction action)
        {
            if (action == System.Data.Linq.ChangeAction.Insert)
            {
                using (DBDataContext db = new DBDataContext())
                {
                    var email = from c in db.Contacts
                                where c.Email == this._newEmail
                                select c.Email;


                    if (email.Count() > 0)
                    {
                        throw new ValidationException("Email addresses must be unique.");
                    }
                }
            }
        }
    }


    public class ContactMetadata
    {
        [DisplayName("Email Address")]
        [Required]
        [RegularExpression(@"^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$",
            ErrorMessage = "A valid email address is required.")]
        [StringLength(150,
            ErrorMessage = "Your email address is too long.")]
        [UIHint("Email")]
        public object Email { get; set; }


        //[UIHint("Url", null, "EnableTest", "false")]
        //public object Url { get; set; }


        [UIHint("Url")]
        public object Url { get; set; }


        [Range(10, 20, ErrorMessage = "Font size must be a value from 10 to 20.")]
        public object PreferredFontSize { get; set; }


        [DisplayFormat(DataFormatString = "{0:g}")]
        public object CreatedOn { get; set; }


        [ScaffoldColumn(false)]
        public object ConcurrencyID { get; set; }
    }


    [ScaffoldTable(false)]
    public partial class aspnet_Applications { }
}


0 Comments
댓글쓰기 폼