45 Unstar Star 100 Fork 35

bouyei / Bouyei.DbFactory

Create your Gitee Account
Explore and code with more than 5 million developers,Free private repositories !:)
Sign up
Clone or download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
readme.md

#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;

Comments ( 15 )

Sign in for post a comment

About

高性能数据库通用访问库,支持sql server ,db2,oracle,my sql,postgresql等多种数据库 spread retract
C# and 4 more languages
Apache-2.0
Cancel

Releases

No release

Gitee Metrics

Contributors

All

Activities

load more
can not load any more
C#
1
https://gitee.com/bouyei/Bouyei.DbFactory.git
git@gitee.com:bouyei/Bouyei.DbFactory.git
bouyei
Bouyei.DbFactory
Bouyei.DbFactory
master

Search