CodeSmith --NetTier 保存主从表实例,当然,至于3级关联的问题还是类似做法,依靠Relationship做级联更新...

 1 None.gif using  System;
 2 None.gif using  System.Data;
 3 None.gif using  System.Configuration;
 4 None.gif using  System.Collections;
 5 None.gif using  System.Web;
 6 None.gif using  System.Web.Security;
 7 None.gif using  System.Web.UI;
 8 None.gif using  System.Web.UI.WebControls;
 9 None.gif using  System.Web.UI.WebControls.WebParts;
10 None.gif using  System.Web.UI.HtmlControls;
11 None.gif using  BlueBeanDemo.Data;
12 None.gif using  BlueBeanDemo.Entities;
13 None.gif
14 None.gif public  partial  class  Purchase_PurchaseCreate : System.Web.UI.Page
15 ExpandedBlockStart.gifContractedBlock.gif dot.gif {
16InBlock.gif    protected void Page_Load(object sender, EventArgs e)
17ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
18InBlock.gif           
19InBlock.gif
20ExpandedSubBlockEnd.gif    }

21InBlock.gif
22InBlock.gif    private void InsertRecord()
23InBlock.gif
24ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
25InBlock.gif//深度保存,可以同时保存父对象和子集
26ExpandedSubBlockStart.gifContractedSubBlock.gif/**////*
27InBlock.gif//DeepSave helper method can help you to save an object and its children in
28InBlock.gif//one call.
29InBlock.gif//*/
30InBlock.gif//using Northwind.DataAccessLayer;
31InBlock.gif//Order order = Order.CreateOrder("ALFKI", 1, DateTime.Now, DateTime.Now,
32InBlock.gif//DateTime.Now, 1, 0.1m, "ship name", "ship address" , "paris", "idf", "75000",
33InBlock.gif//"france");
34InBlock.gif//order.OrderDetailCollection.Add(order.OrderID, 1, 15.6m, 10, 0.02f);
35InBlock.gif//order.OrderDetailCollection.Add(order.OrderID, 2, 122.6m, 43, 0.03f);
36InBlock.gif//DataRepository.OrderProvider.DeepSave(order);
37InBlock.gif//Console.WriteLine("new order saved: orderId is: " + order.OrderID.ToString());
38InBlock.gif
39InBlock.gif        Order order = new Order();
40InBlock.gif
41InBlock.gif        order.OrderID = 9;
42InBlock.gif        order.OrderTime = DateTime.Now;
43InBlock.gif        order.ShipTime = DateTime.Now;
44InBlock.gif        order.CustomerID = 4;
45InBlock.gif        order.ShipPathID = 1;
46InBlock.gif        for (int i = 0; i < 4; i++)
47ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
48InBlock.gif            OrderItem orderitem = new OrderItem();
49InBlock.gif            orderitem.OrderID = 9;
50InBlock.gif            orderitem.ProductID = 1;
51InBlock.gif            orderitem.Price = 2;
52InBlock.gif            orderitem.OrderItemType = 1;
53InBlock.gif            orderitem.ProductUnitID = 1;
54InBlock.gif            orderitem.Amount = 50;
55InBlock.gif
56InBlock.gif
57InBlock.gif            order.OrderItemCollection.Add(orderitem);
58ExpandedSubBlockEnd.gif        }

59InBlock.gif 
60InBlock.gif
61InBlock.gif        DataRepository.OrderProvider.DeepSave(order);
62InBlock.gif        
63InBlock.gif    
64ExpandedSubBlockEnd.gif    }

65InBlock.gif    protected void TextBox2_TextChanged(object sender, EventArgs e)
66ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
67InBlock.gif
68ExpandedSubBlockEnd.gif    }

69InBlock.gif    protected void Button1_Click(object sender, EventArgs e)
70ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
71InBlock.gif        this.InsertRecord();
72ExpandedSubBlockEnd.gif    }

73ExpandedBlockEnd.gif}

74 None.gif

转载于:https://www.cnblogs.com/SlashOut/archive/2007/07/27/834027.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值