Thursday, February 23, 2017

ASP.NET MVC with Dapper ORM

Hi All,
Here's an ASP.NET MVC CRUD(Create/Update/Delete) project with Dapper ORM. The model classes and interface are based from this post Using Dapper ORM in ASP.NET Web Forms with few modifications in Customer class. The updates are adding Display attribute and DisplayFormat attribute to CreditLimit and IntroDate properties.
using System;
using System.ComponentModel.DataAnnotations;

namespace ASPMVCDapper.Models
{
    public class Customer
    {
        public int CustomerID { get; set; }

        [Display(Name="Company Name")]
        public string CompanyName { get; set; }

        [Display(Name = "Address")]
        public string Address { get; set; }

        [Display(Name = "City")]
        public string City { get; set; }

        [Display(Name = "State")]
        public string State { get; set; }

        [Display(Name = "Intro Date")]
        [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
        public DateTime IntroDate { get; set; }

        [Display(Name = "Credit Limit")]
        [DisplayFormat(DataFormatString = "{0:n2}")]
        public decimal CreditLimit { get; set; }
    }
}
Output The source code and Create table script are available in Github ASP.NET MVC With Dapper.

Cheers!

0 comments:

Post a Comment