万金流
初次使用博客园,目前感觉还不错。 不知不觉用了4年零4个月了,越来越喜欢博客园。

如题,每次研究前台技术都要建数据库、连接,还遇到VS各种版本问题,太麻烦。

写这么一个东西,模仿后台Model,上课的时候研究代码层面的内容。甚好。

数据库类:

class myDatabase
    {
        public List<Person> t1 { get; set; }
        public myDatabase()
        {
            t1 = new List<Person>();
            t1.Add(new Person() { Xm = "zs", Nl = 20 });
            t1.Add(new Person() { Xm = "ls", Nl = 18 });
            t1.Add(new Person() { Xm = "ww", Nl = 19 });
        }
    }

实体类:

public class Person
    {
        [Display(Name ="姓名")]
        public string Xm { get; set; }
        [Display(Name = "年龄")]
        public int Nl { get; set; }
    }

别忘了

using System.ComponentModel.DataAnnotations;

不然display属性不生效。这个属性主要是配合

@Html.DisplayNameFor(model => model.Xm)

之类前台代码的显示效果。

 

调试代码:

static void Main(string[] args)
        {
            myDatabase dd=new myDatabase();
            var a = from x in dd.t1 where x.Nl > 18 select x;
            foreach (var item in a)
            {
                Console.WriteLine(item.Xm+"\t"+item.Nl);
            }
            Console.ReadKey();
        }

 

posted on 2019-10-18 20:31  万金流  阅读(376)  评论(0编辑  收藏  举报