本文共 1251 字,大约阅读时间需要 4 分钟。
var id1 = db.Movies.First().ID;var movies1 = db.Movies.ToList();var movie = from m in db.Movieswhere m.ID.Equals(1)select m;movie.First().ID = 2;var id2 = db.Movies.First().ID;//下面设置断点,运行到断点处后,手动向数据库中再添加一条记录var movies2 = db.Movies.ToList();
var movie1 = db.Movies.Find(1);movie1.Price = 100;var movie2 = db.Movies.Find(1);
定义了下面的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 ICollectionMovies { 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();
本文转自JustRun博客园博客,原文链接:http://www.cnblogs.com/JustRun1983/archive/2012/10/09/2716830.html,如需转载请自行联系原作者