如何对不断变化的列的查询结果进行编码? C#MVC

时间:2019-05-27 11:50:39

标签: c# model-view-controller

我不确定如何创建一个表定期更改时将存储结果的模型,并且我不希望用户必须转到代码中来添加或删除列。当前在模型中,我将每个列设置为一个变量。我想更改它,所以如果我运行如下查询:

选择*来自用户

然后将所有结果放入列表或数组变量中,而不是存储在各个变量中。下面的当前代码示例:

    public class User
    {
        public enum SexOfPerson
        {
            Male   = 1,
            Female = 2
        }

        private string    _FirstName;
        public string FirstName 
        {
            get { return _FirstName; } 
            set 
            { 
                 _FirstName = value; 
            } 
        }

        private string _LastName;
        public string LastName
        {
            get { return _LastName; }
            set
            {
                _LastName = value;
            }
        }

        private string _ID;
        public string ID
        {
            get { return _ID; }
            set
            {
               _ID = value;
            }
        }

        private string _Department;
        public string Department
        {
            get { return _Department; }
            set { _Department = value; }
        }

        private SexOfPerson _Sex;
        public SexOfPerson Sex
        {
            get { return _Sex; }
            set { _Sex = value; }
        }


        public User(string firstname, string lastname, string id, string department, SexOfPerson sex)
        {
            FirstName   = firstname;
            LastName    = lastname;
            ID          = id;
            Department  = department;
            Sex         = sex;
        }
    }

可以将其更改为:

public class SQLQueryResult
    {
        public List<string> SQLResult
        {
            get;
            set;
        }
    }


0 个答案:

没有答案