當前位置: 首頁>>代碼示例>>C#>>正文


C# Table<TEntity>.AttachAll方法代碼示例

本文整理匯總了C#中System.Data.Linq.Table<TEntity>.AttachAll方法的典型用法代碼示例。如果您正苦於以下問題:C# Table<TEntity>.AttachAll方法的具體用法?C# Table<TEntity>.AttachAll怎麽用?C# Table<TEntity>.AttachAll使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。


在下文中一共展示了Table<TEntity>.AttachAll方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Northwnd

//引入命名空間
using (Northwnd db = new Northwnd(@"c:\northwnd.mdf"))
{
    // Get original Customer from deserialization.
    var q1 = db.Orders.First();
    string serializedQ = SerializeHelper.Serialize(q1);
    var q2 = SerializeHelper.Deserialize(serializedQ, q1);

    // Track this object for an update (not insert).
    db.Orders.Attach(q2, false);

    // Replay the changes.
    q2.ShipRegion = "King";
    q2.ShipAddress = "1 Microsoft Way";

    // DataContext knows how to update the order.
    db.SubmitChanges();
}
開發者ID:.NET開發者,項目名稱:System.Data.Linq,代碼行數:18,代碼來源:Table.AttachAll

示例2: Northwnd

Customer c = null;
using (Northwnd db = new Northwnd(""))
{
    /* Get both the customer c and the customer's order
    into the cache. */
    c = db.Customers.First();
    string sc = c.Orders.First().ShipCity;
}

using (Northwnd nw2 = new Northwnd(""))
{
    // Attach customers and update the address.
    nw2.Customers.Attach(c, false);
    c.Address = "new";
    nw2.Log = Console.Out;

    /* At SubmitChanges, you will see INSERT requests for all
    Customer c’s orders. */
    nw2.SubmitChanges();
}
開發者ID:.NET開發者,項目名稱:System.Data.Linq,代碼行數:20,代碼來源:Table.AttachAll

示例3: Customer

Customer CustA_File = new Customer();
Customer CustB_File = new Customer();
string xmlFileA = "";
string xmlFileB = "";

// Get the serialized objects.
Customer A = SerializeHelper.Deserialize<Customer>(xmlFileA, CustA_File);
Customer B = SerializeHelper.Deserialize<Customer>(xmlFileB, CustB_File);
List<Order> AOrders = A.Orders.ToList();

using (Northwnd db = new Northwnd(@"c:\northwnd.mdf"))

{
    //Attach all the orders belonging to Customer A all at once.
    db.Orders.AttachAll(AOrders, false);

    // Update the orders belonging to Customer A to show them
    // as owned by Customer B.
    foreach (Order o in AOrders)
    {
        o.CustomerID = B.CustomerID;
    }

    // DataContext can now apply the change of ownership to
    // the database.
    db.SubmitChanges();
}
開發者ID:.NET開發者,項目名稱:System.Data.Linq,代碼行數:27,代碼來源:Table.AttachAll


注:本文中的System.Data.Linq.Table<TEntity>.AttachAll方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。