CodeSmith 4.0 Samples\DatabaseSchema\businessobject.cst,输入表名后生成一个用来操作表的类,但是这个类中用到了一个SqlService sql = new SqlService();,放到vs中提示找不到类型或命名空间名称“SqlService”(是否缺少 using 指令或程序集引用?),不知道怎么解决。求助。
代码如下:
1title#region title
2 /**//// <summary>
3 /// This object represents the properties and methods of a title.
4 /// </summary>
5 public class title
6 {
7 protected string _id;
8 protected string _title = String.Empty;
9 protected string _type = String.Empty;
10 protected string _pub_id = String.Empty;
11 protected decimal _price;
12 protected decimal _advance;
13 protected int _royalty;
14 protected int _ytd_sales;
15 protected string _notes = String.Empty;
16 protected DateTime _pubdate;
17
18 public title()
19 {
20 }
21
22 public title(string id)
23 {
24 SqlService sql = new SqlService();
25 sql.AddParameter("@title_id", SqlDbType.__UNKNOWN__tid, id);
26 SqlDataReader reader = sql.ExecuteSqlReader("SELECT * FROM titles WHERE title_id = '" + id.ToString() + "'");
27
28 if (reader.Read())
29 {
30 this.LoadFromReader(reader);
31 reader.Close();
32 }
33 else
34 {
35 if (!reader.IsClosed) reader.Close();
36 throw new ApplicationException("title does not exist.");
37 }
38 }
39
40 public title(SqlDataReader reader)
41 {
42 this.LoadFromReader(reader);
43 }
44
45 protected void LoadFromReader(SqlDataReader reader)
46 {
47 if (reader != null && !reader.IsClosed)
48 {
49 _id = reader.GetString(0);
50 if (!reader.IsDBNull(1)) _title = reader.GetString(1);
51 if (!reader.IsDBNull(2)) _type = reader.GetString(2);
52 if (!reader.IsDBNull(3)) _pub_id = reader.GetString(3);
53 if (!reader.IsDBNull(4)) _price = reader.GetDecimal(4);
54 if (!reader.IsDBNull(5)) _advance = reader.GetDecimal(5);
55 if (!reader.IsDBNull(6)) _royalty = reader.GetInt32(6);
56 if (!reader.IsDBNull(7)) _ytd_sales = reader.GetInt32(7);
57 if (!reader.IsDBNull(8)) _notes = reader.GetString(8);
58 if (!reader.IsDBNull(9)) _pubdate = reader.GetDateTime(9);
59 }
60 }
61
62 Public Properties#region Public Properties
63 public string Id
64 {
65 get {return _id;}
66 }
67
68 public string title
69 {
70 get {return _title;}
71 set {_title = value;}
72 }
73
74 public string type
75 {
76 get {return _type;}
77 set {_type = value;}
78 }
79
80 public string pub_id
81 {
82 get {return _pub_id;}
83 set {_pub_id = value;}
84 }
85
86 public decimal price
87 {
88 get {return _price;}
89 set {_price = value;}
90 }
91
92 public decimal advance
93 {
94 get {return _advance;}
95 set {_advance = value;}
96 }
97
98 public int royalty
99 {
100 get {return _royalty;}
101 set {_royalty = value;}
102 }
103
104 public int ytd_sales
105 {
106 get {return _ytd_sales;}
107 set {_ytd_sales = value;}
108 }
109
110 public string notes
111 {
112 get {return _notes;}
113 set {_notes = value;}
114 }
115
116 public DateTime pubdate
117 {
118 get {return _pubdate;}
119 set {_pubdate = value;}
120 }
121 #endregion
122
123 public static title Gettitle(string id)
124 {
125 return new title(id);
126 }
127 }
128 #endregion
129
2 /**//// <summary>
3 /// This object represents the properties and methods of a title.
4 /// </summary>
5 public class title
6 {
7 protected string _id;
8 protected string _title = String.Empty;
9 protected string _type = String.Empty;
10 protected string _pub_id = String.Empty;
11 protected decimal _price;
12 protected decimal _advance;
13 protected int _royalty;
14 protected int _ytd_sales;
15 protected string _notes = String.Empty;
16 protected DateTime _pubdate;
17
18 public title()
19 {
20 }
21
22 public title(string id)
23 {
24 SqlService sql = new SqlService();
25 sql.AddParameter("@title_id", SqlDbType.__UNKNOWN__tid, id);
26 SqlDataReader reader = sql.ExecuteSqlReader("SELECT * FROM titles WHERE title_id = '" + id.ToString() + "'");
27
28 if (reader.Read())
29 {
30 this.LoadFromReader(reader);
31 reader.Close();
32 }
33 else
34 {
35 if (!reader.IsClosed) reader.Close();
36 throw new ApplicationException("title does not exist.");
37 }
38 }
39
40 public title(SqlDataReader reader)
41 {
42 this.LoadFromReader(reader);
43 }
44
45 protected void LoadFromReader(SqlDataReader reader)
46 {
47 if (reader != null && !reader.IsClosed)
48 {
49 _id = reader.GetString(0);
50 if (!reader.IsDBNull(1)) _title = reader.GetString(1);
51 if (!reader.IsDBNull(2)) _type = reader.GetString(2);
52 if (!reader.IsDBNull(3)) _pub_id = reader.GetString(3);
53 if (!reader.IsDBNull(4)) _price = reader.GetDecimal(4);
54 if (!reader.IsDBNull(5)) _advance = reader.GetDecimal(5);
55 if (!reader.IsDBNull(6)) _royalty = reader.GetInt32(6);
56 if (!reader.IsDBNull(7)) _ytd_sales = reader.GetInt32(7);
57 if (!reader.IsDBNull(8)) _notes = reader.GetString(8);
58 if (!reader.IsDBNull(9)) _pubdate = reader.GetDateTime(9);
59 }
60 }
61
62 Public Properties#region Public Properties
63 public string Id
64 {
65 get {return _id;}
66 }
67
68 public string title
69 {
70 get {return _title;}
71 set {_title = value;}
72 }
73
74 public string type
75 {
76 get {return _type;}
77 set {_type = value;}
78 }
79
80 public string pub_id
81 {
82 get {return _pub_id;}
83 set {_pub_id = value;}
84 }
85
86 public decimal price
87 {
88 get {return _price;}
89 set {_price = value;}
90 }
91
92 public decimal advance
93 {
94 get {return _advance;}
95 set {_advance = value;}
96 }
97
98 public int royalty
99 {
100 get {return _royalty;}
101 set {_royalty = value;}
102 }
103
104 public int ytd_sales
105 {
106 get {return _ytd_sales;}
107 set {_ytd_sales = value;}
108 }
109
110 public string notes
111 {
112 get {return _notes;}
113 set {_notes = value;}
114 }
115
116 public DateTime pubdate
117 {
118 get {return _pubdate;}
119 set {_pubdate = value;}
120 }
121 #endregion
122
123 public static title Gettitle(string id)
124 {
125 return new title(id);
126 }
127 }
128 #endregion
129