zoukankan      html  css  js  c++  java
  • Entity Framework练习题

    1. 问题: 变量id2的值是1,还是2? 假如如下面的注释操作,movies2有几条记录?里面会包含ID = 1的记录吗?

    24073653

    var id1 = db.Movies.First().ID;
    
    var movies1 = db.Movies.ToList();
    
    var movie = from m in db.Movies
    
    where m.ID.Equals(1)
    
    select m;
    
    movie.First().ID = 2;
    
    var id2 = db.Movies.First().ID;
    
    //下面设置断点,运行到断点处后,手动向数据库中再添加一条记录
    
    var movies2 = db.Movies.ToList();

    2. 问题: movie2的price是多少?

     
     24073653
     
    var movie1 = db.Movies.Find(1);
    movie1.Price = 100;
    var movie2 = db.Movies.Find(1);

    3. 下面movie1和move2的类型一样吗?User1和User2类型一样吗?

    定义了下面的Model

        public class Movie
        {
            public int ID { get; set; }
            public string Title { get; set; }
            public DateTime ReleaseDate { get; set; }
            public string Genre { get; set; }
            public decimal Price { get; set; }
            public virtual Category Category { get; set; }
        }
    
        public class Category
        {
            public int ID { get; set; }
            public string Name { get; set; }
            public virtual ICollection<Movie> Movies { get; set; }
        }
         
        public class User
        {
            public string Name{get;set;}
        }

    使用不同的方式创建Movie, User对象

    var movie1 = db.Movies.Create();
    var movie2 = new Movie();
    
    var user1 = db.User.Create();
    var user2 = new User();

     

    Creative Commons License

    本文基于署名 2.5 中国大陆许可协议发布,欢迎转载,演绎或用于商业目的,但是必须保留本文的署名justrun(包含链接)。如您有任何疑问或者授权方面的协商,请给我留言

  • 相关阅读:
    HDU-5384
    UVALive 5099
    ZOJ-2753
    HUD-5379
    HDU-5360
    HDU-5351
    HDU-5335
    HDU-5317
    HDU-2487
    常用十六进制颜色对照表代码查询
  • 原文地址:https://www.cnblogs.com/JustRun1983/p/2716830.html
Copyright © 2011-2022 走看看