Entity Framework Core Lolita
来源:互联网 发布:数据透视表实例 编辑:程序博客网 时间:2024/05/22 16:01
这是Entity Framework Core的一个轻量的扩展,提供批量更新和删除操作的支持。而且这个库出自中国一位MVP之手,虽然内容是英文,也很简单,相信你也能看懂。
This is a light-weight extension which provides bulk update and delete operations for Entity Framework Core.
View source on GitHub
Download from NuGet
Getting Started
① Add Pomelo.EntityFrameworkCore.Lolita
package into your project.json
. There are many different special versions for different EF database provider:
Pomelo.EntityFrameworkCore.Lolita.MySql
Pomelo.EntityFrameworkCore.Lolita.SqlServer
Pomelo.EntityFrameworkCore.Lolita.PostgreSQL
Pomelo.EntityFrameworkCore.Lolita.Sqlite
② Configure your DbContext
For ASP.NET Core developers, you can Use lolita extensions when adding the DbContext into services collection:
services.AddDbContext<Models.SampleContext>(x =>{ x.UseMySql(
"server=localhost;database=lolita;uid=root;pwd=yourpwd;"); x.UseMySqlLolita();});
For .NET Core developers, you can override the OnConfiguring of DbContext to use lolita:
protected override void OnConfiguring(
DbContextOptionsBuilder optionsBuilder)
{ optionsBuilder.UseMySql(
"server=localhost;database=lolita;uid=root;pwd=yourpwd;"); optionsBuilder.UseMySqlLolita();
base.OnConfiguring(optionsBuilder);}
③ There are many different extended methods for updating a column or bulk deleting.
Updating:
db.Posts .Where(x => x.Time <= DateTime.Now) .SetField(x => x.IsPinned).WithValue(false) .Update();
You can also use the following methods to update a field:
Plus SET [x] = [x] + @value Numeric only Subtract SET [x] = [x] - @value Numeric only Multiply SET [x] = [x] * @value Numeric only Divide SET [x] = [x] / @value Numeric only Mod SET [x] = [x] % @value Numeric only Prepend SET [x] = @value + [x] String only Append SET [x] = [x] + @value String only AddMilliseconds SET [x] = DATEADD(ms, @value, [x]) DateTime only AddSeconds SET [x] = DATEADD(ss, @value, [x]) DateTime only AddMinutes SET [x] = DATEADD(mi, @value, [x]) DateTime only AddHours SET [x] = DATEADD(hh, @value, [x]) DateTime only AddDays SET [x] = DATEADD(dd, @value, [x]) DateTime only AddMonths SET [x] = DATEADD(mm, @value, [x]) DateTime only AddYears SET [x] = DATEADD(yy, @value, [x]) DateTime only
Deleting:
db.Users .Where(x => db.Posts.Count(y => y.UserId == x.Id) == 0) .Where(x => x.Role == UserRole.Member) .Delete();
Contribute
One of the easiest ways to contribute is to participate in discussions and discuss issues. You can also contribute by submitting pull requests with code changes.
License
MIT
相关文章:
全球首发免费的MySql for Entity Framework Core
.NET Core 使用Dapper 操作MySQL
在.NET Core中使用MySQL5.7的JSON类型字段
原文地址:http://www.1234.sh/post/ef-core-lolita
.NET社区新闻,深度好文,微信中搜索dotNET跨平台或扫描二维码关注
- Entity Framework Core Lolita
- Entity Framework Core使用迁移
- Entity Framework Core 数据迁移
- Entity Framework Core 批处理语句
- Entity Framework Core 批处理语句
- Entity Framework Core 命名约定
- Entity Framework Core 使用体会
- ASP.NET Core如何使用Entity Framework
- Entity Framework Core 数据库自动迁移API
- Entity Framework Core 2.0 新特性
- Entity Framework Core 2.0 全局查询过滤器
- Entity Framework Core Like 查询揭秘
- Entity Framework Core 2.0 全局查询过滤器
- Entity Framework Core 2.0 新特性
- Entity Framework Core 生成跟踪列
- Entity Framework Core 1.1 升级通告
- Asp.Net Core-使用Entity Framework
- Entity Framework Core 2.0 使用入门
- 在.NET开发面向Oracle数据库的应用程序
- Win10上运行Docker
- 【送书活动】机器学习项目开发实战
- Activity生命周期的坑
- Asp.net Core基于MVC框架实现PostgreSQL操作
- Entity Framework Core Lolita
- 你必须知道的EF知识和经验
- 做嵌入式经典网站!
- java 内存分析
- .NET Core系列 :3 、使用多个项目
- 复选框的全选和反选
- 微软准备开源PowerShell
- 分布式基础通信协议:paxos,totem和gossip
- 使用Visual Studio 2015 开发ASP.NET MVC 5 项目部署到Mono/Jexus