GithubHelp home page GithubHelp logo

bionstt / lolita Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pomelofoundation/lolita

0.0 0.0 0.0 102 KB

A light-weight extension which provides bulk update and delete operations for Entity Framework Core.

License: MIT License

Batchfile 0.25% PowerShell 1.78% Shell 1.15% C# 96.82%

lolita's Introduction

Lolita

Travis build status AppVeyor build status NuGet Join the chat at https://gitter.im/PomeloFoundation/Home

A light-weight extension which provides bulk update and delete operations for Entity Framework Core.

Getting Started

① Add Pomelo.EntityFrameworkCore.Lolita package into your project.json. There are many different special versions for different EF database providers:

  • 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.

using Microsoft.EntityFrameworkCore;

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:

Method SQL Hint
WithValue SET [x] = @value
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

lolita's People

Contributors

applenele avatar giuseppepiscopo avatar yukozh avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.