public bool Add(string cityname, bool isactive) { using (AuthorizeEntities context = new AuthorizeEntities()) { try { var citys =new City(); citys.CityID=Guid.NewGuid(); citys.CityName = cityname; citys.IsActive = isactive; context.AddToCity(citys); context.SaveChanges(); return true; } catch (Exception e) { throw e; } } }
/// <summary> /// 创建新的 City 对象。 /// </summary> /// <param name="cityID">CityID 属性的初始值。</param> /// <param name="cityName">CityName 属性的初始值。</param> /// <param name="isActive">IsActive 属性的初始值。</param> public static City CreateCity(global::System.Guid cityID, global::System.String cityName, global::System.Boolean isActive) { City city = new City(); city.CityID = cityID; city.CityName = cityName; city.IsActive = isActive; return city; }
/// <summary> /// 用于向 City EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet<T> 属性的 .Add 方法。 /// </summary> public void AddToCity(City city) { base.AddObject("City", city); }