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>-->ifexists(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>-->usingSystem;
usingGentle.Framework;
namespaceConGentleStudy
{
/**////<summary>
///BaseExample的摘要说明。
///</summary>
publicclassBaseExample
{
[STAThread]
staticvoidMain(string[]args)
{
Console.WriteLine("创建人实例。");
Peoplespeople=newPeoples("xuanfeng");
Console.WriteLine("创建人实例。");
Broker.Insert(people);
Console.WriteLine("创建人实例。");
people.PeopleName="peizunyou";
Console.WriteLine("更新人的信息。");
Broker.Update(people);
Console.WriteLine("创建返回实例信息的Key!");
Keykey=newKey("Peoples",typeof(Peoples),true,"PeopleName","peizunyou");
Console.WriteLine(key.Count.ToString());
Console.WriteLine("创建人实例!");
Peoplespeople1=newPeoples();//必须先实例化申请到空间,下步才不会出错。
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=newKey(typeof(Peoples),true,"PeopleID",people1.PeopleID);
Broker.Remove(typeof(Peoples),key_rem);//主意,Key中提供的字段PeopleID是表中的主键,删除才有效!
Console.WriteLine("演示完成,按任何键退出!");
Console.Read();
}
}
[TableName("Peoples")]
publicclassPeoples
{
stringname;
intid;
publicPeoples(int_id,string_name)
{
this.name=_name;
this.id=_id;
}
publicPeoples(string_name)
{
this.name=_name;
}
publicPeoples()
{
}
[TableColumn("PeopleID",true),PrimaryKey(AutoGenerated=true)]
publicintPeopleID
{
get{returnthis.id;}
set{this.id=value;}
}
[TableColumn("PeopleName",true)]
publicstringPeopleName
{
get{returnthis.name;}
set{this.name=value;}
}
}
}
分享到:
相关推荐
Gentle.NET是一个开源的优秀O/R Mapping的对象持久化框架。Gentle.NET是一个关系数据库中立的(RDBMS indenpendent)对象持久化框架。它具有以下特征: ·自动构建SQL ·自动创建实体对象 ·用于创建定制查询...
gentle.net mygeneration NHibernate
Gentle.NET是一个独立于数据库的对象持久性框架。 它具有广泛的功能集,出色的性能和相当完整的文档。 功能包括SQL生成,对象构造/缓存/ uniqing,验证等。
ASP.NET 2.0使用Web Part创建应用程序之二(共二) 体验 .net2.0 的优雅(2) -- ASP.net 主题和皮肤 NET2.0系列介绍(一).NET 2.0 中Web 应用程序主题的切换 ASP.NET 2.0 中Web 应用程序主题的切换 2.0正式版中...
MyGeneration 是一款不错的ORM和代码生成工具...使用MyGeneration 可以为Gentle.NET, Opf3, NHibernate等生成ORM架构或ORM文件,为多种数据库生成存储过程,为.Net项目生成C#、VB.NET 程序代码,PHP、HTML等页面代码。
A Gentle Introduction to ROS,ROS初级入门资料,介绍的比较系统
使用MyGeneration 可以为Gentle.NET, Opf3, NHibernate等生成ORM架构或ORM文件,为多种数据库生成存储过程,为.Net项目生成C#、VB.NET 程序代码,PHP、HTML等页面代码。 MyGeneration 具有以下的特性: 1.支持多种...
lisp的入门教程A Gentle Introduction To Symbolic Computation
通用编译器的自动构造软件gentle97教程
Learning a new language and a new framework can be daunting. What you need is a guide to help leverage your existing knowledge and skills, and show you just what you need to know to get up and running...
a-gentle-introduction-to-neural-networks-with-python
一套不错的opencart 模板,opencart template Gentle,包括 PSD 源文件。 适合opencart 1.5, 可以参考学习,也可以自行修改。
.NET 4.6, and Visual Studio 2015, Get off the ground quickly, with a gentle introduction to C#, Visual Studio, and a step-by-step walkthrough and explanation of how to make your first C# program....
Learn to control the tools and tricks of programming in C#, including the .NET framework, dealing with compiler errors, and hunting down bugs in your program. Master the needed skills by taking on a ...
A Gentle Introduction to Category Theory 1994 Fokkinga
一篇关于进化计算的概述 A Gentle Introduction to Evolutionary Computation
介绍了machine learning中gentle boosting的基本思想和算法,并附有相关matlab程序和例子。 运用cross validation来选取iteration的次数。
Learn to control the tools and tricks of programming in C#, including the .NET framework, dealing with compiler errors, and hunting down bugs in your program. Master the needed skills by taking on a ...
gentle_tensorflow, Tensorflow简介 Gentlest Tensorflow目标Tensorflow ( TF ) 尝试将深入学习的功力放入世界各地开发人员的手中。 它有一个初学者&和高级教程,以及Udacity课程。 Gentlest Tensorflow尝试克
地理信息系统(GIS)的初学者指南,该指南使用开放源Quantum GIS作为示例。