1.appsettings.json 添加配置节点 "FreeSqlExtend": { "DBConnectionList": [ { "Name": "cms", "ConnectionStr": "Server=172.168.16.1*****************************", "DbType": "MySql" }, { "Name": "shop", "ConnectionStr": "Server=172.168.16.1*****************************", "DbType": "MySql", "SlaveConnectionStr": [ "Server=172.168.16.1*****************************", "Server=172.168.16.1*****************************", "Server=172.168.16.1*****************************" ] } ] } 2.startup中初始化服务 ////初始化数据库访问层 var serviceProvider = services.BuildServiceProvider(); FreeSqlHelperStatic.InitStaticDB(new SettingHelper(serviceProvider.GetService<IConfiguration>())); 3.如果是多数据库系统,可以定义一个子类,方便多库操作.提高开发效率,不定义不影响使用. public class SqlHelper : FreeSqlHelperStatic { public static IFreeSql cms { get { return StaticDB.GetDB("cms"); } } public static IFreeSql shop { get { return StaticDB.GetDB("shop"); } } } 4.配置完成,可以使用 SqlHelper或FreeSqlHelperStatic的静态方法,访问数据库了. var list = SqlHelper.Select<Article>() .WhereIf(!string.IsNullOrEmpty(title), w => w.Title.Contains(title)) .Take(20) .OrderByDescending(o => o.ID) .ToList();
-
Notifications
You must be signed in to change notification settings - Fork 0
License
easy999000/FreeSqlExtend
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
No description, website, or topics provided.
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published