menu

Saturday, September 24, 2016

Code First CRUD in Entity Framework using ASP.NET

Steps to implement code first CRUD in entity framework. (Download Sample App)
1. Install entity framework liberary from NuGet.
2. Create model classes and context class
3. Create table to store student information and add connection string in Web.config file.
CREATE TABLE [dbo].[Students](
       [ID] [int] IDENTITY(1,1) NOT NULL,
       [Name] [nvarchar](max) NULL,
       [DOB] [datetime] NOT NULL,
       [Photo] [varbinary](max) NULL,
       [Height] [decimal](18, 2) NULL,
       [Weight] [real] NULL,
       CONSTRAINT [PK_Students] PRIMARY KEY CLUSTERED ([ID] ASC)
       WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
       IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,
       ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
4. Create UI in Asp.net WebForm as shown above. (Download .aspx and aspx.cs)
5. Create a handler to bind binary data to grid view. (Download handler code)

No comments:

Post a Comment