Gentle.net Framework 入門二(基礎示例)
系統
1615 0
1.
一個基本的示例
通過該示例可以撐握以下內容:
1)
Gentle.net
是怎么把對象(類)和關系數據庫
(SQL)
關聯起來的
.
2)
使用
Gentle.net
插入,更新,返回實例信息,和刪除數據
.
本示例中以人為實例,包括人
ID
和姓名
.
附上建表腳本
示例表代碼
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
if
exists(select
*
fromdbo.sysobjectswhereid
=
object_id(N
'
[dbo].[Peoples]
'
)andOBJECTPROPERTY(id,N
'
IsUserTable
'
)
=
1
)
droptable[dbo].[Peoples]
GO
CREATETABLE[dbo].[Peoples](
[PeopleID][
int
]IDENTITY(
1
,
1
)NOTNULL,
[PeopleName][
char
](
10
)COLLATEChinese_PRC_CI_ASNOTNULL
)ON[PRIMARY]
GO
接著附上代碼,相關使用請看代碼。
<!-- google_ad_client = "pub-6628499292856412"; google_ad_width = 468; google_ad_height = 60; google_ad_format = "468x60_as"; google_ad_type = "text_image"; google_ad_channel = ""; google_color_border = "000000"; google_color_bg = "FFFFFF"; google_color_link = "191919"; google_color_text = "000000"; google_color_url = "008000"; //-->
示例代碼
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
using
System;
using
Gentle.Framework;
namespace
ConGentleStudy
{
/**/
///
<summary>
///
BaseExample的摘要說明。
///
</summary>
public
class
BaseExample
{
[STAThread]
static
void
Main(
string
[]args)
{
Console.WriteLine(
"
創建人實例。
"
);
Peoplespeople
=
new
Peoples(
"
xuanfeng
"
);
Console.WriteLine(
"
創建人實例。
"
);
Broker.Insert(people);
Console.WriteLine(
"
創建人實例。
"
);
people.PeopleName
=
"
peizunyou
"
;
Console.WriteLine(
"
更新人的信息。
"
);
Broker.Update(people);
Console.WriteLine(
"
創建返回實例信息的Key!
"
);
Keykey
=
new
Key(
"
Peoples
"
,
typeof
(Peoples),
true
,
"
PeopleName
"
,
"
peizunyou
"
);
Console.WriteLine(key.Count.ToString());
Console.WriteLine(
"
創建人實例!
"
);
Peoplespeople1
=
new
Peoples();
//
必須先實例化申請到空間,下步才不會出錯。
people1.PeopleName
=
"
xiamfe
"
;
Console.WriteLine(
"
返回一個人實例的信息!
"
);
//
Peoplespeople1=(Peoples)Broker.RetrieveInstance(typeof(Peoples),key),這樣是將出錯
people1
=
(Peoples)Broker.RetrieveInstance(
typeof
(Peoples),key);
//
返回一個實例信息。
Console.WriteLine(
"
輸出人的姓名
"
);
Console.WriteLine(people1.PeopleName);
Console.WriteLine(
"
刪除信息!
"
);
Keykey_rem
=
new
Key(
typeof
(Peoples),
true
,
"
PeopleID
"
,people1.PeopleID);
Broker.Remove(
typeof
(Peoples),key_rem);
//
主意,Key中提供的字段PeopleID是表中的主鍵,刪除才有效!
Console.WriteLine(
"
演示完成,按任何鍵退出!
"
);
Console.Read();
}
}
[TableName(
"
Peoples
"
)]
public
class
Peoples
{
string
name;
int
id;
public
Peoples(
int
_id,
string
_name)
{
this
.name
=
_name;
this
.id
=
_id;
}
public
Peoples(
string
_name)
{
this
.name
=
_name;
}
public
Peoples()
{
}
[TableColumn(
"
PeopleID
"
,
true
),PrimaryKey(AutoGenerated
=
true
)]
public
int
PeopleID
{
get
{
return
this
.id;}
set
{
this
.id
=
value;}
}
[TableColumn(
"
PeopleName
"
,
true
)]
public
string
PeopleName
{
get
{
return
this
.name;}
set
{
this
.name
=
value;}
}
}
}
Gentle.net Framework 入門二(基礎示例)
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061
微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元