Follow me on Twitter at Twitter.com/wbm
FYI, I'm blogging most of my stuff over at More Wally now.
You might want to add my rss feed to your reader at:http://morewally.com/cs/blogs/wallym/rss.aspx
ASP.NET Podcast Show #127 - Dynamic Data - Wallace B. McClure

Wallace B. McClure

All About Wally McClure - The musings of Wallym on Web, HTML5, Mobile, Xamarin.iOS, Xamarin.Android, and Windows Azure.

News

Visual Studio Magazine Column Personal Blog

.NET

Book Authors

Business

Family

Friends

Georgia Tech Bloggers

Personal

Archives

ASP.NET Podcast Show #127 - Dynamic Data

Subscribe to All!

Subscribe to WMV.

Subscribe to M4V (iPod).

Subscribe to MP3.

Download WMV.

Download M4V (iPod).

Download MP3.

Original Url: http://aspnetpodcast.com/CS11/blogs/asp.net_podcast/archive/2008/11/09/asp-net-podcast-show-127-dynamic-data.aspx

Show Notes:

Source Code:

Global.asax:

model.RegisterContext(typeof(db35sp1Entities), new ContextConfiguration() { ScaffoldAllTables = true });

Metadata class:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;

namespace Dynamic_Data
{
    [DisplayColumn("Name")]
    [MetadataType(typeof(tbItemMetaData))]
    public partial class tbItem
    {
        private class tbItemMetaData
        {
            [DisplayName("Item Display Name")]
            [StringLength(30)]
            [Required(ErrorMessage="Item name is required.")]
            public object Name { get; set; }

            [DisplayFormat(DataFormatString="{0:c}")]
            [Range(0, 500, ErrorMessage="Standard Cost should be between {1} and {2}.")]
            public object Price { get; set; }
        }

        // Note the naming convention of On X Changing and the nullable value.
        partial void OnPriceChanging(decimal? value)
        {
            if (value < 0)
            {
                throw (new ValidationException("Price must be positive, afterall we aren't paying you to take it."));
            }
        }
    }

    [MetadataType(typeof(tbOrderMetaData))]
    public partial class tbOrder
    {
        private class tbOrderMetaData
        {
            [ScaffoldColumn(true)]
            [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}")]
            public object DateUpdated { get; set; }
        }
    }  
}
 

Comments

No Comments