Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
hi is it possible insert some specific fields from one table to a class in mvc?
for example i have a tbl_User . can i insert just Name in MyClass?


C#
public class MyClass
      {
             //i mean can i put some fields of tbl_User instead below code .
          public List<tbl_User> tbl_User { get; set; }

      }
Posted
Comments
Zoltán Zörgő 13-Aug-13 15:53pm    
Of course you can. But you forgot to add some important constraints in your question so without context your question makes no sense neither my answer.

1 solution

Your class should be the model of the data in your table. You should have a class User with Properties such as Name. Then you can write a method to get a List of Users to access each User's Name.
C#
class User
    {
        private string name;
        public User() { }

        public string Name
        {
            get { return this.name; }
        }

        public static List<user> GetUserList()
        {
            List<user> userList = new List<user>();
            //get data
            return userList;
        }
    }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900