1 Star 0 Fork 1

andyshao / SinGooCMSAdo

forked from singoocms / SinGooCMSAdo 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

SinGooCMSAdo

SinGooCMS.Ado 支持netstandard2.1和net framework 4.6.1,原生sql语句操作,支持SqlServer、MySql、Sqlite、Oracle

1、引用 SinGooCMS.Ado

using SinGooCMS.Ado;
using SinGooCMS.Ado.Interface;

2、配置 appsetting.json

//.net core配置
"ConnectionStrings": {
  "ProviderName": "Sqlite",
  //"SQLConnSTR": "server=(local);database=SinGooCMS-v1.6;uid=sa;pwd=123;Application Name=SinGooCMS;pooling=true;min pool size=5;max pool size=512;connect timeout = 20;",
  //"SQLConnSTR": "server=localhost;database=SinGooCMSv16;uid=root;pwd=123456;SslMode=None;",
  "SQLConnSTR": "Data Source=db/singootop.db",
  //"SQLConnSTR": "data source=localhost:1521;user id=jsonlee;password=123;;min pool size=5;max pool size=512;"
  //"DistributedCacheConnStr": "server=(local);database=SinGooCMS-v1.6;uid=sa;pwd=123;Application Name=SinGooCMS;pooling=true;min pool size=5;max pool size=512;connect timeout = 20;",
  "RedisExchangeHosts": "127.0.0.1:6379,allowadmin=true"
}

//.net framework配置
<connectionStrings>
  <add name="SQLConnSTR" providerName="SqlServer" connectionString="server=(local);database=SinGooCMS-v1.6;uid=sa;pwd=123"/>
  <!--<add name="SQLConnSTR" providerName="MySql" connectionString="server=localhost;database=SinGooCMSv16;uid=root;pwd=123456;SslMode=None;"/>
  <add name="SQLConnSTR" providerName="Oracle" connectionString="data source=localhost:1521;user id=jsonlee;password=123;min pool size=5;max pool size=512;" />
  <add name="SQLConnSTR" providerName="Sqlite" connectionString="Data Source=db/singootop.db"/>-->
</connectionStrings> 

ProviderName 支持四种数据库:SqlServer、MySql、Sqlite、Oracle SQLConnSTR 数据库连接字符串

3、使用

//使用默认的字符串
IDbAccess dbSqlServerAccess => DbProvider.DbAccess;
//也可以使用指定的连接字符串
IDbAccess dbSqlServerAccess => DbProvider.Create(DbProviderType.SqlServer, "server=(local);database=SinGooCMS-v1.6;uid=sa;pwd=123");
//使用其它数据库
IDbAccess dbMySqlAccess => DbProvider.Create(DbProviderType.MySql, "server=localhost;database=singoocmsv16;uid=root;pwd=123456;SslMode=None;");

//CRUD
//查询
var model=dbSqlServerAccess.Find<DbMaintenanceTestInfo>(10);
var model=dbSqlServerAccess.FindAsync<DbMaintenanceTestInfo>(10);

var model=dbSqlServerAccess.GetModel<DbMaintenanceTestInfo>("select * from cms_User where UserName='jsonlee'");
var model=dbSqlServerAccess.GetModelAsync<DbMaintenanceTestInfo>("select * from cms_User where UserName='jsonlee'");

DataTable dt=dbSqlServerAccess.GetDataTable("select * from cms_User");

//分页
var pagerData=dbSqlServerAccess.GetPagerList<DbMaintenanceTestInfo>("", "AutoID desc", 2, 10);
var pagerData=dbSqlServerAccess.GetPagerListAsync<DbMaintenanceTestInfo>("", "AutoID desc", 2, 10);

//增加
dbSqlServerAccess.InsertModel(new DbMaintenanceTestInfo() { UserName = "jsonlee" });
dbSqlServerAccess.InsertModelAsync(new DbMaintenanceTestInfo() { UserName = "jsonlee" });

//修改
dbSqlServerAccess.UpdateModel(new DbMaintenanceTestInfo() { AutoID=10,UserName="刘备" });
dbSqlServerAccess.UpdateModelAsync(new DbMaintenanceTestInfo() { AutoID=10,UserName="刘备" });

//删除
dbSqlServerAccess.DeleteModel(new DbMaintenanceTestInfo() { AutoID=15 });
dbSqlServerAccess.DeleteModelAsync(new DbMaintenanceTestInfo() { AutoID=15 });

dbSqlServerAccess.DeleteModel<DbMaintenanceTestInfo>(15);
dbSqlServerAccess.DeleteModelAsync<DbMaintenanceTestInfo>(15);

关于实体类特性
[Table("DbMaintenanceTest")]
public class DbMaintenanceTestInfo
{
    [Key]
    public int AutoID { get; set; }
    public string UserName { get; set; }
}

Table("数据库表名") 表示实体类映射的数据库的表名
Key 表示当前列是主键列
NotMapped 表示不需要映射到数据库字段,一般是自定义的属性

关于主键
1)如果主键是自增整型,应该加上 NotMapped 特性,这样插入数据是会忽略些列
2)非自增需要插入数据的主键,不要有 NotMapped 特性。

移除性能分析

2020-11-07

MIT License Copyright (c) 2021 SinGooCMS Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

SinGooCMS.Ado 支持netstandard2.1和net framework 4.6.1,原生sql语句操作,支持SqlServer、MySql、Sqlite、Oracle 展开 收起
C#
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
C#
1
https://gitee.com/andyshao/SinGooCMSAdo.git
git@gitee.com:andyshao/SinGooCMSAdo.git
andyshao
SinGooCMSAdo
SinGooCMSAdo
master

搜索帮助