前言:
-----------------------------------------------
相关讨论组入口: http://www.pixysoft.net/ (点击进入)
功能简介:
1. 支持SQLite,Access,MySQL,SqlServer,Oracle的操作。
2. 支持同时对多个数据库操作,并相互交互。
3. 支持表转简单的对象,进行简易ORM操作。
4. 是缓存、orm等后期模块基础。
快速入门:
using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Framework.XSchEmA.Entity;
using Pixysoft.Framework.XSchEmA;
using System.Data;
using Pixysoft.Tools;
using Pixysoft.Framework.Reflection;
using System.Xml.Serialization;
namespace Pixysoft.Framework.Noebe
{
class quickstart
{
/// <summary>
/// 创建数据库
/// </summary>
public void test_001()
{
//初始化数据库链接信息
DatabaseInfo info = new DatabaseInfo();
info.Filename = AppDomain.CurrentDomain.BaseDirectory + "\\sqlite.db";
info.DatabaseType = DatabaseType.SQLite;
DatabaseSchema db = new DatabaseSchema(info);
TableSchema table = new TableSchema("HELLO");
table.Columns.Add(new ColumnSchema("HELLO", "COLUMN1", new DataTypeSchema("TEXT")));
table.Columns.Add(new ColumnSchema("HELLO", "COLUMN2", new DataTypeSchema("TEXT")));
table.Columns.Add(new ColumnSchema("HELLO", "COLUMN3", new DataTypeSchema("TEXT")));
db.Tables.Add(table);
db.PrimaryKeys.Add(new PrimaryKeySchema("HELLO_PK", "HELLO", "COLUMN1"));
db.Build();
//部署
XSchemaManager.SQLiteSchema.Schema.Commit(info, db);
}
/// <summary>
/// 增删改查
/// </summary>
public void test_002()
{
NoebeConfiguration config = new NoebeConfiguration();
config.DatabaseType = DatabaseType.SQLite;
config.Filename = AppDomain.CurrentDomain.BaseDirectory + "\\sqlite.db";
NoebeManager.Reload(config);
//插入
DataTable table = NoebeManager.Instance.GetEntity("HELLO");
DataRow row = table.NewRow();
row["COLUMN1"] = GlobalTimer.Instance.GetGlobalTime().ToString();
row["COLUMN2"] = "column";
row["COLUMN3"] = DateTime.Now;
table.Rows.Add(row);
NoebeManager.Instance.NoebeCommand.Insert(table);
//查询
INoebeCommand command = NoebeManager.Instance.NoebeCommand;
command.SQL = "SELECT * FROM HELLO WHERE COLUMN2 = :COLUMN2";
command.Parameters.Add("COLUMN2", "column");
DataTable searchtable = command.ExecuteReader();
Console.WriteLine(searchtable.Rows[0][0].ToString());
//更新
searchtable.Rows[0][2] = "column3";
NoebeManager.Instance.NoebeCommand.Update(searchtable);
Console.WriteLine(NoebeManager.Instance.NoebeCommand.Select("HELLO").Rows.Count);
//删除
NoebeManager.Instance.NoebeCommand.Delete(searchtable);
Console.WriteLine(NoebeManager.Instance.NoebeCommand.Select("HELLO").Rows.Count);
}
/// <summary>
/// 测试简易的ORM
/// </summary>
public void test_003()
{
NoebeConfiguration config = new NoebeConfiguration();
config.DatabaseType = DatabaseType.SQLite;
config.Filename = AppDomain.CurrentDomain.BaseDirectory + "\\sqlite.db";
NoebeManager.Reload(config);
//插入
QuickstartHello hello = ReflectionManager.CreatePojo<QuickstartHello>();
hello.Column1 = GlobalTimer.Instance.GetGlobalTime().ToString();
hello.Column2 = "column";
hello.Column3 = "column";
NoebeManager.Instance.EntityNoebeCommand.Insert(hello);
//查询
IEntityNoebeCommand command = NoebeManager.Instance.EntityNoebeCommand;
command.SQL = "SELECT * FROM HELLO WHERE COLUMN2 = :COLUMN2";
command.Parameters.Add("COLUMN2", "column");
List<QuickstartHello> hellos = command.ExecuteReader<QuickstartHello>();
Console.WriteLine(hellos[0].Column2);
}
}
[XmlRoot("HELLO")]
public interface QuickstartHello : IEntityBase
{
string Column1 { get;set;}
string Column2 { get;set;}
string Column3 { get;set;}
}
using System.Collections.Generic;
using System.Text;
using Pixysoft.Framework.XSchEmA.Entity;
using Pixysoft.Framework.XSchEmA;
using System.Data;
using Pixysoft.Tools;
using Pixysoft.Framework.Reflection;
using System.Xml.Serialization;
namespace Pixysoft.Framework.Noebe
{
class quickstart
{
/// <summary>
/// 创建数据库
/// </summary>
public void test_001()
{
//初始化数据库链接信息
DatabaseInfo info = new DatabaseInfo();
info.Filename = AppDomain.CurrentDomain.BaseDirectory + "\\sqlite.db";
info.DatabaseType = DatabaseType.SQLite;
DatabaseSchema db = new DatabaseSchema(info);
TableSchema table = new TableSchema("HELLO");
table.Columns.Add(new ColumnSchema("HELLO", "COLUMN1", new DataTypeSchema("TEXT")));
table.Columns.Add(new ColumnSchema("HELLO", "COLUMN2", new DataTypeSchema("TEXT")));
table.Columns.Add(new ColumnSchema("HELLO", "COLUMN3", new DataTypeSchema("TEXT")));
db.Tables.Add(table);
db.PrimaryKeys.Add(new PrimaryKeySchema("HELLO_PK", "HELLO", "COLUMN1"));
db.Build();
//部署
XSchemaManager.SQLiteSchema.Schema.Commit(info, db);
}
/// <summary>
/// 增删改查
/// </summary>
public void test_002()
{
NoebeConfiguration config = new NoebeConfiguration();
config.DatabaseType = DatabaseType.SQLite;
config.Filename = AppDomain.CurrentDomain.BaseDirectory + "\\sqlite.db";
NoebeManager.Reload(config);
//插入
DataTable table = NoebeManager.Instance.GetEntity("HELLO");
DataRow row = table.NewRow();
row["COLUMN1"] = GlobalTimer.Instance.GetGlobalTime().ToString();
row["COLUMN2"] = "column";
row["COLUMN3"] = DateTime.Now;
table.Rows.Add(row);
NoebeManager.Instance.NoebeCommand.Insert(table);
//查询
INoebeCommand command = NoebeManager.Instance.NoebeCommand;
command.SQL = "SELECT * FROM HELLO WHERE COLUMN2 = :COLUMN2";
command.Parameters.Add("COLUMN2", "column");
DataTable searchtable = command.ExecuteReader();
Console.WriteLine(searchtable.Rows[0][0].ToString());
//更新
searchtable.Rows[0][2] = "column3";
NoebeManager.Instance.NoebeCommand.Update(searchtable);
Console.WriteLine(NoebeManager.Instance.NoebeCommand.Select("HELLO").Rows.Count);
//删除
NoebeManager.Instance.NoebeCommand.Delete(searchtable);
Console.WriteLine(NoebeManager.Instance.NoebeCommand.Select("HELLO").Rows.Count);
}
/// <summary>
/// 测试简易的ORM
/// </summary>
public void test_003()
{
NoebeConfiguration config = new NoebeConfiguration();
config.DatabaseType = DatabaseType.SQLite;
config.Filename = AppDomain.CurrentDomain.BaseDirectory + "\\sqlite.db";
NoebeManager.Reload(config);
//插入
QuickstartHello hello = ReflectionManager.CreatePojo<QuickstartHello>();
hello.Column1 = GlobalTimer.Instance.GetGlobalTime().ToString();
hello.Column2 = "column";
hello.Column3 = "column";
NoebeManager.Instance.EntityNoebeCommand.Insert(hello);
//查询
IEntityNoebeCommand command = NoebeManager.Instance.EntityNoebeCommand;
command.SQL = "SELECT * FROM HELLO WHERE COLUMN2 = :COLUMN2";
command.Parameters.Add("COLUMN2", "column");
List<QuickstartHello> hellos = command.ExecuteReader<QuickstartHello>();
Console.WriteLine(hellos[0].Column2);
}
}
[XmlRoot("HELLO")]
public interface QuickstartHello : IEntityBase
{
string Column1 { get;set;}
string Column2 { get;set;}
string Column3 { get;set;}
}
下期预告:
Pixysoft.Framework.Noebe.Orm 纯ORM操作,使用自主研制的AOP框架,性能与非ORM操作一致!!!
什么叫做完美?这个就是完美。
附件下载:
http://www.boxcn.net/shared/j074tcyvex
SVN: