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

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

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

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

65    protected void TextBox2_TextChanged(object sender, EventArgs e)
66    {
67
68    }

69    protected void Button1_Click(object sender, EventArgs e)
70    {
71        this.InsertRecord();
72    }

73}

74
posted @ 2007-07-27 18:24  Slashout  阅读(588)  评论(0编辑  收藏  举报