1 Unstar Star 0 Fork 35

王振宇 / Bouyei.DbFactoryC#

forked from bouyei / Bouyei.DbFactory 
Create your Gitee Account
Explore and code with more than 5 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Without author's permission, this code is only for learning and cannot be used for other purposes.
c#多种数据库通用访问框架(.net framework和.net core),支持ef和ado.net方式访问,ado.net支持sql server ,db2,oracle,my sql,postgresql等多种数据库. spread retract

Clone or download
bouyei authored version
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
readme.md

#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"
});

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();

        //查询
       var sql= sqlProvider.Select<User>()
            .From<User>().Where<User>(x => x.Id == 1).SqlString;

        //修改
        sql = sqlProvider.Update<User>()
            .Set<User>(new User() { Name = "bouyei", UserName = "hkj" })
            .Where<User>(x => x.Id == 1).SqlString;

        //删除
        sql = sqlProvider.Delete()
            .From<User>().Where<User>(x => x.Name == "bouyei").SqlString;

        //插入
        sql = sqlProvider.Insert<User>()
            .Values<User>(new User[] {
            new User() { Name ="hello", UserName="aileenyin.com" }
            ,new User() { Name="bouyei",UserName="jiang"} }).SqlString;

Comments ( 0 )

Sign in for post a comment

C#
1
https://gitee.com/jordencodecloud/dbproviderfactory.git
git@gitee.com:jordencodecloud/dbproviderfactory.git
jordencodecloud
dbproviderfactory
Bouyei.DbFactory
master

Search