处理oralce,sqlserver,access及其他常用数据库,
1、web.config配置数据库连接字符串,以及数据库类型:
//未检验 //检验可以
//经检验可以
组件读取connectionStrings节点的配置的时候会根据providerName来判断是哪种数据库。
- Sql server 2000:Dos.ORM.SqlServer
- Sql server 2005/2008及以上:Dos.ORM.SqlServer9
- MS Access:Dos.ORM.MsAccess
- Sqlite:Dos.ORM.Sqlite
- Oracle:Dos.ORM.Oracle
- MySql:Dos.ORM.MySql
2、全局声明
public class DB { public static readonly DbSession Context = new DbSession("DosConn"); }
3、开始使用Dos.ORM
var list = DB.Context.From().ToList();
4、使用示例
全局配置:public class DB{ public static readonly DbSession Context = new DbSession("DosConn");}查询示例(Lambda表达式写法):DB.Context.From() .Select(d => new { d.ID, d.Price }) //select ID,Price from TableName .Where(d => (d.ID == 2 && d.Name != "itdos" && d.Name.In("com","net","cn") && ) || d.Sex != null) // where (id=2 and Name<>'itdos' and Name in('com','net','cn')) or Sex is not null .GroupBy(d => new { d.Name, d.Sex }) //group by Name,Sex .OrderBy(d => new { d.CreateTime, d.Name }) //order by CreateTime,Name .Having(d => d.Name != '') //having Name<>'' .Top(5) .Page(10, 2) //分页返回结果 每页10条返回第2页数据 .ToList(); //返回实体列表 //.ToFirst(); //返回第一个实体 //.ToFirstDefault(); //返回第一个实体,如果为null,则默认实例化一个 //.ToDataSet(); //返回DataSet //.ToDataReader(); //返回IDataReader //.ToDataTable(); //返回DataTable //.ToScalar(); //返回单个值插入示例://单个实体插入var newModel = new Dos.Model.TableName(){ ID = Guid.NewGuid(), Name = "ITdos.com"};var count1 = DB.Context.Insert (newModel); //批量插入var newList = new List ();newList.Add(new Dos.Model.TableName(){ ID = Guid.NewGuid(), Name = "ITdos.com"});var count2 = DB.Context.Insert (newList); 删除示例:var count1 = DB.Context.Delete (d => d.ID == 1); 修改示例:var uptModel = DB.Context.From ().Where(d => d.ID == 1).ToFirst();uptModel.Attach();uptModel.Name = "ITdos.net";var count1 = DB.Context.Update (uptModel);