SelectListItem Helper to create selectlistitems from enum

first, we create a extension method to get the descriptions of enum values.

public static string ToDescription<T>(this T enumValue)
            where T : struct, IConvertible, IComparable, IFormattable // Criteria for Enums
        {
            var fieldInfo = enumValue.GetType().GetField(enumValue.ToString());
            var attributes = fieldInfo.GetCustomAttributes(typeof(DescriptionAttribute), false).Cast<DescriptionAttribute>().ToList();
            return attributes.Any() ? attributes.First().Description : enumValue.ToLabel();
        }

second, create the selectlistitems from the enum.

public static List<SelectListItem> GetItemsForEnum<TEnum>(int? selectedValue = null, string defaultText = "")
            where TEnum : struct, IConvertible, IComparable, IFormattable // Criteria for Enums
        {
            var results = new List<SelectListItem>();
            var values = Enum.GetValues(typeof (TEnum));
 
            if (!string.IsNullOrEmpty(defaultText ))
                results.Add(new SelectListItem { Text = defaultText , Value = "" });
 
            foreach (var value in values)
            {
                var name = ((TEnum)value).ToDescription();
                var selected = (selectedValue != null) && selectedValue.Equals((int)value);
                results.Add(new SelectListItem { Text = name, Value = ((int)value).ToString(), Selected = selected });
            }
            return results;
        }

Override EF 5 database mapping

public class UserRepo
{
    private UserContext _context;
    public UserRepo(UserContext context)
    {
        _context = context;
    }
 
    public User Save(User user)
    {
        if (user.Id <= 0)
        {
            _context.Users.Add(user);
        }
        else
        {
            _context.Users.Attach(user);
        }
        return user;
    }
}
 
public class User
{
    public int Id { get; set; }
    public string Name { get; set; }
}
 
public class UserMapping : EntityTypeConfiguration<User>
{
    public UserMapping()
    {
        HasKey(p => p.Id);
        Property(p => p.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity).HasColumnName("Id");
        Property(p => p.Name).HasMaxLength(100);
 
        ToTable("User");
    }
}
 
public class UserContext : DbContext
{
    public DbSet<User> Users { get; set; }
 
    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Configurations.Add(new UserMapping());
    }
 
    public UserRepo UserRepo
    {
        get
        {
            return new UserRepo(this);
        }
    }
}

SQL script to view sizes of all tables

SELECT
    t.NAME AS TableName,
    p.rows AS RowCounts,
    SUM(a.total_pages) * 8 AS TotalSpaceKB, 
    SUM(a.used_pages) * 8 AS UsedSpaceKB, 
    (SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB
FROM
    sys.tables t
INNER JOIN     
    sys.indexes i ON t.OBJECT_ID = i.object_id
INNER JOIN
    sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id
INNER JOIN
    sys.allocation_units a ON p.partition_id = a.container_id
WHERE
    t.NAME NOT LIKE 'dt%'
    AND t.is_ms_shipped = 0
    AND i.OBJECT_ID > 255 
GROUP BY
    t.Name, p.Rows
ORDER BY
    t.Name