-1

In my project I need 3 Name of Tables and Columns like this :

Tables :User , News , Roles
Columns : Date,Title,Id

and store this column Name and Table name in another Table . Is best use Enum for stor this value like this :

public enum TableName
{
    News,
    Role,
    User
}
public enum ColumnName
{
    Date,
    Id,
    Title
}

or create a two table for store this ?

which one is better ?

I need Table and Column name show in dropdown and save it in database . I use Code First . i dont Use Reflection for showing Columns because I dont show All columns to user.

I need this for save OrderSetting for example Set Order for News Table Like this :

Table :'News' , Columns :'Date', Type:`Desc`

Always should a row for each table .

Psar Tak
  • 682
  • 1
  • 9
  • 27
  • For code first POCO your table name should be the class name and the columns the properties in the class. Enums are not sensible in your scenario. Reflect the class to get the properties if required: http://stackoverflow.com/questions/737151/how-to-get-the-list-of-properties-of-a-class – Murray Foxcroft Dec 24 '15 at 08:33
  • It totally depends on what is the functionality you're going to achieve, what is the size of your DB and application, because you wouldn't like to hit db for this if it is just a simple pre defined drop down values and its not a feature on which your application's other modules will depend. – Shaharyar Dec 24 '15 at 08:34
  • @MurrayFoxcroft thanks , whats you idea for do this . I want this table name and column name for `OrderSetting Data` – Psar Tak Dec 24 '15 at 08:36

1 Answers1

1

Someting along the lines of

  public class MyTable
    {
        public string TableName { get; set; }
        public List<string> Columns { get; set; }

        public MyTable()
        {
            Columns = new List<string>();
        }

        public void PopulateFromType(Type t)
        {
            TableName = t.Name;

            foreach (var prop in t.GetProperties())
            {
                Columns.Add(prop.Name);
            }
        }
    }

    public class Foo
    {
        public int A { get; set; }
        public string B { get; set; }
    }

    public class Processor
    {
        public void AddFoo()
        {
            var myTable = new MyTable();
            myTable.PopulateFromType(typeof(Foo));
        }
    }
Murray Foxcroft
  • 12,785
  • 7
  • 58
  • 86