当前位置: 首页>>代码示例>>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;未经允许,请勿转载。