我可以从一个表插入一些特定的字段到一个类 [英] can i insert some specific fields from one table to a class

查看:73
本文介绍了我可以从一个表插入一些特定的字段到一个类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi
是否可以将一个特定字段从一个表插入到mvc中的类?

例如我有一个tbl_User。我可以只在MyClass中插入姓名吗?





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?


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

      }

推荐答案

您的类应该是表中数据的模型。您应该有一个具有属性的用户类,例如Name。然后你可以编写一个方法来获取用户列表来访问每个用户的名字。

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.
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;
        }
    }


这篇关于我可以从一个表插入一些特定的字段到一个类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆