Create C# Model From TSQL Table

Find Tips and tricks on how to better use the Zeus IDE. Feel free to post your own tips but please do not post bug reports, feature requests or questions here.
Post Reply
jussij
Site Admin
Posts: 2498
Joined: Fri Aug 13, 2004 5:10 pm

Create C# Model From TSQL Table

Post by jussij »

The attached zip file contains a TSQL stored procedure that can be used to create a C# Model for a given TSQL table.

usage: EXEC [dbo].[sp_ModelFromTable] tblExample

Running that stored procedure will produced the model shown below:

Code: Select all

using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace Database.Model
{
    [Table("tblExample", Schema = "dbo")]
    public class tblExampleModel
    {
        [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        Column("ID")]
        public int ID { get; set; }
 
        Column("Name")]
        public string Name { get; set; }
    }
}
sp_ModelFromTable.zip
(1.51 KiB) Downloaded 10 times
Post Reply