DBLayer wizard ,一个国外写的数据库访问和实体映射的自动生成工具
2005-11-19 23:38
796 查看
Introduction
This is the first version of DBLayer Wizard. It's a tool to generate the Data Layer in N-tier architectures in CS file format. This helps developers to save their time from writing the same code every time they work in a new project. We tried to provide the best ways in coding and data access patterns to satisfy speed, ease of use, reliability, robustness, and portability.As we stated above, our main goal for this tool was to save developer time in N-tier applications using .NET languages. We also tried very hard to cover many methods for data access; for that we studied many data layer frameworks, so we provide here many ways and options for database operations.
Features
Creates a class that is calledDBwhich includes common data access functionality in any application like executing in-line SQL, executing a Stored Procedure and executing a transaction.
Creates a class for each table that performs the most common operations like select by primary key, select by foreign key, select all records, insert, update and delete.
Creates a class to execute Stored Procedures. For each Stored Procedure, gives the ability to return (
DataSet,
DataReader, or a return value).
Generated code is based on templates so developer can customize with save and open customized templates.
All generated CS files saved to folder that you choose.
Using the DataLayer wizard code generator
Define SQL Server information (server name, authentication method, database name).Select tables for which you want to generate a .NET class for.
Select Stored Procedures for which you want to generate methods for.
Select the return data types for tables [
DataSetor
DataReaderor both] and for Stored Procedures.
Define the template which will be used to generate the .NET code.
Define the folder which the code will be generated in.
Using the generated code from your application
Here we will see some examples of how to use the generated code. We are working on the NorthWind as the sample DB. This should act as a guide for the class developer.How to execute in-line SQL:
//DBlayer is the namespace of generated code //all classes and method are static method //Execute Common method form the base class DataSet ds=DBLayer.DB.Execute("SELECT * FROM Customers"); //Execute Scalar (Avg,Count,Sum,..) object result=DBLayer.DB.ExecuteScalar("SELECT COUNT(*) FROM Customers"); //Execute Non Query like (Insert,Update,Delete) int AffectedRows=DBLayer.DB.ExecuteNonQuery(insert sql statment);As you see above, all methods are
staticand the base namespace is
DBlayer.
How to insert into a table: As you will see, in the insert operation, we have three different ways for inserting.
//Insert bool result= DBLayer.DBTableShippers.Insert("New Tech","123456"); //Insert DataRow DataRow row=DBLayer.DBTableShippers.GetSchema(); row["CompanyName"]="New Tech"; row["Phone"]="123456"; bool result= DBLayer.DBTableShippers.Insert(row); //Insert DataTable DataTable table=DBLayer.DBTableShippers.GetSchemaTable(); DataRow row1=table.NewRow(); row1["CompanyName"]="New Tech"; row1["Phone"]="123456"; table.Rows.Add(row1); DataRow row2=table.NewRow(); row2["CompanyName"]="New Tech"; row2["Phone"]="123456"; table.Rows.Add(row2); bool result= DBLayer.DBTableShippers.Insert(table);
How to update data in a table:
//Update bool result=DBLayer.DBTableShippers.Update(1,"Home","12365"); //Update DataRow DataRow row=DBLayer.DBTableShippers.GetSchema(); row["ShipperID"]=1; row["CompanyName"]="New Tech"; row["Phone"]="123456"; bool result=DBLayer.DBTableShippers.Update(row); //Update Data Table DataTable table=DBLayer.DBTableShippers.GetSchemaTable(); DataRow row1=table.NewRow(); row1["ShipperID"]=1; row1["CompanyName"]="New Tech"; row1["Phone"]="123456"; table.Rows.Add(row1); DataRow row2=table.NewRow(); row2["ShipperID"]=2; row2["CompanyName"]="Ok"; row2["Phone"]="123456"; table.Rows.Add(row2); bool result=DBLayer.DBTableShippers.Update(table);
How to delete data from a table:
//Delete All the Rows int DeletedRows=DBLayer.DBTableOrders.DeleteAll(); //Delete By PK bool result=DBLayer.DBTableOrders.DeleteByPK(int.Parse(txtPK.Text)); //Delete By FK bool result=DBLayer.DBTableOrders.DeleteByFK(txtFK.Text);
How to select from a table:
//Select All Rows DataSet ds= DBLayer.DBTableOrders.SelectAll(); //Select By Primary Key DataSet ds= DBLayer.DBTableOrders.SelectByPK(int.Parse(txtPKds.Text)); //Select By Foreign Key DataSet ds= DBLayer.DBTableOrders.SelectByFK(txtFKds.Text);
How to execute a transaction:
//the method takes array of strings which //is the SQL statements of the transaction bool result=DBLayer.DB.ExecuteTransaction(txtSQL.Lines);
相关详细说明和源代码请访问http://www.codeproject.com/cs/database/DBLayer_Wizard.asp
相关文章推荐
- Mybatis自动生成实体类和实体映射工具
- 利用反射+特性实现简单的实体映射数据库操作类(还未做自动生成SQL语句部分)
- MDWiki —— 一个可以自动生成左侧菜单并在线访问的工具
- 通过mybatis工具generatorConfig.xml自动生成实体,DAO,映射文件
- 在eclipse中使用MyBatis Geneator自动生成出对应数据库的实体与映射文件
- 关于Hibernate不能自动生成数据库表-POJO和映射文件正确但是访问对应表出错-的原因
- 一个自动生成Hibernate ORM映射文件的工具函数
- 通过mybatis工具generatorConfig.xml自动生成实体,DAO,映射文件
- 【.NetCore学习】ASP.NET Core EF Core2.0 DB First现有数据库自动生成实体Context
- 推荐一个好的数据库工具Embarcadero DBArtisan
- c#利用反射+特性实现简单的实体映射数据库操作类实现自动增删改查(一)
- 基于数据库的自动化生成工具,自动生成JavaBean、自动生成数据库文档等(v5.0.0版)
- 一个用户SQL Server2000/2005的好工具_——数据库发布向导(Database Publishing Wizard)
- 自己写的一个代码自动生成工具_java版_源码下载
- Mybatis根据数据库表自动生成实体类和xml映射文件
- 发布一个自动生成实体类,接口类,数据底层和业务类的小工具
- 安装doxygen(一个自动文档生成工具)+Graphviz图形可视化软件
- Hibernate 根据实体映射文件自动生成表
- 数据库组件 Hxj.Data (二)(实体生成工具)