Code Monkey home page Code Monkey logo

light.data2's Introduction

LightData

dotnet license nuget

English | 简体中文 |

Light.Data is a lightweight ORM framework which based on dotnet standard 2.0, through to the entity model class Attribute or configuration files relate data table. Use core class DataContext was carried out on the table to CURD operation.

Supported Database

Database Introduce
SqlServer Need to install nuget install Light.Data.Mssql library, SqlServer 2008 support or above
Mysql Need to install nuget install Light.Data.Mysql library
Postgre Need to install nuget install Light.Data.Postgre library

Guide Document

Basic Operation

  • Basic CURD
  • Batch CUD
  • Supports transaction processing
  • Supports data fields default value and automatic timestamp
  • Supports data fields read-write control
  • THe Query results specify class or anonymous class output
  • The query results insert into the data table directly
var context = new DataContext();
// query single data
var item = context.Query<TeUser>().Where(x => x.Id == 10).First();
// query collection datas
var list = context.Query<TeUser>().Where(x => x.Id > 10).ToList();
// create date
var user = new TeUser() {
    Account = "foo",
    Password = "bar"
};
context.Insert(user);
// update data
user.Password = "bar1";
context.Update(user);
// delete data
context.Delete(user);

Data Aggregation

  • Single-Column data directly aggregate
  • Multi-Column data grouped aggregate
  • Format the grouped field
  • Aggregate data insert into the data table directly
// basic
var list = context.Query<TeUser> ()
                  .Where (x => x.Id >= 5)
                  .GroupBy (x => new LevelIdAgg () {
                      LevelId = x.LevelId,
                      Data = Function.Count ()
                   })
                  .ToList ();

// date format
var list = context.Query<TeUser> ()
                  .GroupBy (x => new RegDateFormatAgg () {
                      RegDateFormat = x.RegTime.ToString("yyyy-MM-dd"),
                      Data = Function.Count ()
                   })
                  .ToList ();	

Join-Table Query

  • Multi-Table join, Support inner join, left join and right join
  • Support query results and aggregate data join together
  • Join query results specify class or anonymous class output
  • join query results insert into the data table directly
// inner join
var join = context.Query<TeUser> ()
                  .Join<TeUserExtend>((x,y) => x.Id == y.Id);

// aggregate data join entity table          
var join = context.Query<TeMainTable>()
                  .GroupBy(x => new {
                      MId = x.MId,
                      Count = Function.Count(),
                   })
                  .Join<TeSubTable>((x, y) => x.MId == y.Id);

Execute SQL

  • Use SQL and Stored Procedures directly
  • Supports object parameters
  • Query results specify class or anonymous class output
  • Stored Procedures support use output parameters
// basic parameter
var sql = "update Te_User set NickName=@P2 where Id=@P1";
var ps = new DataParameter[2];
ps[0] = new DataParameter("P1", 5);
ps[1] = new DataParameter("P2", "abc");
var executor = context.CreateSqlStringExecutor(sql, ps);
var ret = executor.ExecuteNonQuery();

// object parameter
var sql = "update Te_User set NickName={nickname} where Id={id}";
var executor = context.CreateSqlStringExecutor(sql, new { nickname = "abc", id = 5 });
var ret = executor.ExecuteNonQuery();

light.data2's People

Contributors

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