Giter Site home page Giter Site logo

entityframeworkcore.bootkit's Introduction

EntityFrameworkCore.BootKit

n'] Join the chat at https://gitter.im/publiclab/publiclab Documentation Status NuGet

EntityFrameworkCore Boot Kit (EFBK) is a quick start database connect library for using .NET EntityFrameworkCore.

Features:

  • Inherits from EntityFrameworkCore Triggers to enable entries update notfication.
  • Support mulitple databases like MySql, SQL Server, Sqlite, PostgreSql, MongoDB, Amazon Redshift, AWS Aurora and InMemory.
  • Support dynamic linq to query and update database.
  • Support read/write seperated mode. Randomly choose multiple slaves.
  • Multiple database with distributed transaction supported, and MySQL multiple databases/tables sharding supported.
  • Tracking entry change history.
  • Built-in DbFactory with access control list (ACL) hook.

Get started

How to install

PM> Install-Package EntityFrameworkCore.BootKit

How to use

  1. Define entity
  public class PizzaOrder : DbRecord, IDbRecord
  {
	[MaxLength(32)]
	public String OrderNumber { get; set; } 

	[MaxLength(64)]
	public String CustomerName { get; set; }
	
	[Required]
	public DateTime CreatedTime { get; set; }
	
	[ForeignKey("OrderId")]
	public List<PizzaType> PizzaTypes { get; set; }
  }
  1. Init data context
  var db = new Database();
  AppDomain.CurrentDomain.SetData("Assemblies", new string[] { "EntityFrameworkCore.BootKit.UnitTest" });

  // bind as much data context as you can
  db.BindDbContext<IDbRecord, DbContext4Sqlite>(new DatabaseBind
  {
	MasterConnection = new SqliteConnection($"Data Source={Directory.GetCurrentDirectory()}\\..\\..\\..\\..\\bootkit.db"),
	CreateDbIfNotExist = true
  });

  db.BindDbContext<IDbRecord, DbContext4PostgreSql>(new DatabaseBind
  {
      MasterConnection = new NpgsqlConnection("Server=; Port=5439;User ID=;Password=;Database=;SSL Mode=Require;Trust Server Certificate=True;Use SSL Stream=True"),
  });
  1. Retrieve record
  var order = db.Table<PizzaOrder>().Include(x => x.PizzaTypes).FirstOrDefault();
  1. Retrieve record by table name
  var table = db.Table("PizzaOrder");
  var pizzaOrder = table.First() as PizzaOrder;
  1. Update record in transaction
  int row = db.DbTran(() =>
  {
    var po = db.Table<PizzaOrder>().Find(PIZZA_ORDER_ID);
    po.CreatedTime = DateTime.UtcNow
  });
  1. Update record in Patch function
  int row = db.DbTran(() =>
  {
	var patch = new DbPatchModel
	{
		Table = "PizzaOrder",
		Id = PIZZA_ORDER_ID
	};

	patch.Values.Add("CreatedTime", dt);
	db.Patch<IDbRecord>(patch);
  });
  1. Implement IRequireDbPermission to interupt update
  2. View raw sql
  string sql = table.ToSql();
  1. Added MongoDb support
  db.BindDbContext<IDbRecord, DbContext4MongoDb>(new DatabaseBind
  {
	MasterConnection = new MongoDbConnection("mongodb://user:password@localhost:27017/db"),
  });
  var collection = db.Collection<MongoDbCollectionTest>().FirstOrDefault();

  // Add new record
  db.Collection<MongoDbCollection>().InsertOne(new MongoDbCollection
  {
    Id = Guid.NewGuid().ToString(),
    Name = "Pizza"
  });

  // Update record
  db.Collection<MongoDbCollection>().UpdateOne(x => x.Name == "Pizza", x => x.Name, "Pizza 2");
  1. Support Amazon Redshift
  db.BindDbContext<IDbRecord, DbContext4Redshift>(new DatabaseBind
  {
      string connString = "Server=*.us-east-1.redshift.amazonaws.com; Port=5439;User ID=;Password=;Database=;Server Compatibility Mode=Redshift;SSL Mode=Require;Trust Server Certificate=True;Use SSL Stream=True";
      MasterConnection = new NpgsqlConnection(connString),
  });

Documentation

https://entityframeworkcorebootkit.readthedocs.io

entityframeworkcore.bootkit's People

Contributors

deep-blue-2013 avatar dependabot[bot] avatar memoryfraction avatar oceania2018 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

entityframeworkcore.bootkit's Issues

How to select field of type super from redshift ?

Hello,
I try to select a field of type super from redshift and I get the following error:
Unhandled Exception is caught, args: IsTerminating[True] , System.NotSupportedException: The field 'payload' has type 'super', which is currently unknown to Npgsql. You can retrieve it as a string by marking it as unknown, please see the FAQ.

My model:

        [Table("livescore")]
        public class Livescore : IDbRecord
        {
            [Key]
            [Column("message_guid")]
            public string MessageGuid { get; set; }

            [Column("payload")]
            public string Payload { get; set; }
        }

How I try to select it:

            var db = new Database();
            AppDomain.CurrentDomain.SetData("Assemblies", new string[] { "Archive.Tester" });
            
            db.BindDbContext<IDbRecord, DbContext4Redshift>(new DatabaseBind
            {
                MasterConnection = new NpgsqlConnection("Server=host; Port=port;User ID=user;Password=pass;Database=db;Server Compatibility Mode=Redshift")
            });

            var data = db.Table<Livescore>().FirstOrDefault();

Getting the error on the last line, any idea?

How to Init db in web api?

How to Init db in web api? In ConfigureServices with DI or in a controller directly?Db should be reused?

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.