对于一个单独实体的通常操作有3种:添加新的实体.修改实体以及删除实体. 1.添加新的实体 Entity Framework Code First添加新的实体通过调用DbSet.Add()方法来实现. using (var ctx = new PortalContext()) { var province = new Province { ProvinceNo = ", ProvinceName = "测试" }; ctx.Provinces.Add(province); ct…
1.添加外键关联实体 1>.添加新的Province及City实体 using (var ctx = new PortalContext()) { var city1 = new City { CityNo = ", CityName = "测试城市1" }; var city2 = new City { CityNo = ", CityName = "测试城市2" }; var province = new Province { Prov…