/// <summary> /// Create a new Territories object. /// </summary> /// <param name="territoryID">Initial value of the TerritoryID property.</param> /// <param name="territoryDescription">Initial value of the TerritoryDescription property.</param> public static Territories CreateTerritories(global::System.Int64 territoryID, global::System.String territoryDescription) { Territories territories = new Territories(); territories.TerritoryID = territoryID; territories.TerritoryDescription = territoryDescription; return territories; }
/// <summary> /// Deprecated Method for adding a new object to the Territories EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToTerritories(Territories territories) { base.AddObject("Territories", territories); }
// // NOTE: Used to test the fix for ticket [ccfa69fc32]. // private static int EFTransactionTest(bool add) { // // NOTE: Some of these territories already exist and should cause // an exception to be thrown when we try to INSERT them. // long[] territoryIds = new long[] { 1, 2, 3, 4, 5, // NOTE: Success 6, 7, 8, 9, 10, // NOTE: Success 1576, 1577, 1578, 1579, 1580, // NOTE: Success 1581, 1730, 1833, 2116, 2139, // NOTE: Fail (1581) 2140, 2141 // NOTE: Skipped }; if (add) { using (northwindEFEntities db = new northwindEFEntities()) { using (TransactionScope scope = new TransactionScope()) { // // NOTE: *REQUIRED* This is required so that the // Entity Framework is prevented from opening // multiple connections to the underlying SQLite // database (i.e. which would result in multiple // IMMEDIATE transactions, thereby failing [later // on] with locking errors). // db.Connection.Open(); foreach (int id in territoryIds) { Territories territories = new Territories(); territories.TerritoryID = id; territories.TerritoryDescription = String.Format( "Test Territory #{0}", id); territories.Regions = db.Regions.First(); db.AddObject("Territories", territories); } try { #if NET_20 db.SaveChanges(false); #else db.SaveChanges(SaveOptions.None); #endif } catch (Exception e) { Console.WriteLine(e); } finally { scope.Complete(); db.AcceptAllChanges(); } } } } else { using (northwindEFEntities db = new northwindEFEntities()) { bool once = false; #if NET_20 // // HACK: We cannot use the Contains extension method within a // LINQ query with the .NET Framework 3.5. // var query = from t in db.Territories orderby t.TerritoryID select t; foreach (Territories territories in query) { if (Array.IndexOf(territoryIds, territories.TerritoryID) == -1) continue; if (once) Console.Write(' '); Console.Write(territories.TerritoryID); once = true; } #else var query = from t in db.Territories where territoryIds.AsQueryable<long>().Contains<long>(t.TerritoryID) orderby t.TerritoryID select t; foreach (Territories territories in query) { if (once) Console.Write(' '); Console.Write(territories.TerritoryID); once = true; } #endif } } return 0; }