常规操作
安装 SmartSql
Install-Package SmartSql
安装 SmartSql.DIExtension
Install-Package SmartSql.DIExtension
配置SmartSqlConfig.xml
写库(Write)必选 唯一节点
读库(Read)可选 多节点配置
Postgresql
Postgresql 客户端 Npgsql
Install-Package Npgsql
"1.0" encoding="utf-8" xml version=<SmartSqlMapConfig xmlns="http://SmartSql.net/schemas/SmartSqlMapConfig.xsd"> <Settings IsWatchConfigFile="true" /> <Database> <!--ParameterPrefix:[SqlServer:@ | MySQL:? |Oracle::|Postgresql:@] --> <DbProvider Name="SqlClientFactory" ParameterPrefix="@" Type="Npgsql.NpgsqlFactory,Npgsql"/> <Write Name="WriteDB" ConnectionString="Server=localhost;Port=5432;User Id=postgres;Password=Rocher2016; Database=SmartSqlDB;"/> </Database> <SmartSqlMaps> <SmartSqlMap Path="Maps/" Type="Directory"></SmartSqlMap> </SmartSqlMaps>
</SmartSqlMapConfig>
MYSQL
安装mysql 客户端 Mysql.Data
Install-Package Mysql.Data
配置SmartSqlMapConfig.xml
MSSQL
注入依赖
services.AddSmartSql();services.AddRepositoryFactory();services.AddRepositoryFromAssembly((options) =>{options.AssemblyString = "SmartSql.Starter.Repository";});
定义仓储接口
尽情享用
作者:Ahoo Wang (阿虎)
Github: https://github.com/Ahoo-Wang/
SmartSql(高性能、高生产力,超轻量级的ORM!): https://github.com/Ahoo-Wang/SmartSql
SmartCode(不只是代码生成器!): https://github.com/Ahoo-Wang/SmartCode
相关文章:
如何通过本地化事件正确实现微服务内部强一致性,事件总线跨微服务间最终一致性
SmartCode 正式开源,不只是代码生成器!
原文地址:https://www.cnblogs.com/Ahoo-Wang/p/SmartSql-best-practice.html
.NET社区新闻,深度好文,欢迎访问公众号文章汇总 http://www.csharpkit.com