类别:控件工具
日期:2020-09-22 浏览:2404 评论:0
1、.Net 统一数据库接口库,支持 ORM 和 ado.net 方式;ado.net(包含)支持 SQL server,DB2,Oracle,MySQL,Postgresql,access 等;
2、支持.net Core 2.0,.net framework,.net standard 2.0+
3、简单查询Linq表达式
#Bouyei.DbFactory 基于.net framework 4.6.1+
#Bouyei.DbFactoryCore基于.net core2.2+
#Bystd.DbFactory 基于.net standard 2.0+
#1、Ado使用例子
string connectionString = "Data Source=.;Initial Catalog=testdb;User ID=sa;Password=bouyei;";
IAdoProvider adoProvider = AdoProvider.CreateProvider(connectionString);
var rt = adoProvider.Query(new Parameter(){ CommandText = "select * from MemUser"});
//删除
var del= adoProvider.Delete<user>(x => x.uname =="hkj" && (x.sex==Sex.Female ||x.uage==30));
//插入
var insert = adoProvider.Insert<user>(new user() { name="bouyei", age=30 });
//查询
var users = adoProvider.Query<user>(x => 1 == 1);
//查询条数
var users = adoProvider.QueryToTake<user>(x => 1 == 1,10);
foreach (DataRow dr in rt.Result.Rows){ Console.WriteLine(string.Join(",", dr.ItemArray));}
#基于EF的ORM需要再配置文件加相应实体映射dll路径,详细看demo代码例子
IOrmProvider ormProvider = OrmProvider.CreateProvider(ProviderType.SqlServer, connectionString);
var items= ormProvider.Query<DbEntity.User>("select * from MemUser").ToList();foreach(var item in items){ Console.WriteLine(item.uName);}Console.ReadKey();
#sql表达式生成例子 //生成简单查询脚本 ISqlProvider sqlProvider = SqlProvider.CreateProvider();
//MappedName 测试
var sqls = sqlProvider.Insert<UserDto>().Values(new UserDto[] { new UserDto() { Pwd="ds", UserName="d" } }).SqlString;
//查询
var sql = sqlProvider.Select<User>().From().Where(x => x.id == 1).Top(FactoryType.PostgreSQL, 10).SqlString;
//修改
sql = sqlProvider.Update<User>().Set(new User() { name = "bouyei" }).Where<User>(x => x.id == 1 || (x.name == "b" && x.no == 2)).SqlString;
//删除
sql = sqlProvider.Delete().From<User>().Where(x => x.name == "bouyei").SqlString;
//插入
sql = sqlProvider.Insert<User>().Values(new User[] { new User() { name ="hello", age=12 } ,new User() { name="bouyei",age=23} }).SqlString;
下载地址
https://gitee.com/bouyei/Bouyei.DbFactory
发表评论 / 取消回复