Giter Club home page Giter Club logo

kros.libs's Introduction

kros.libs's People

Contributors

burgyn avatar erikparso avatar jardohornak avatar jurajknutelsky avatar lukassefcik avatar michalau avatar mikado3780 avatar ml13 avatar satano avatar sincoda avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

kros.libs's Issues

IDbSet.BulkUpdate() throws System.InvalidOperationException when connection is not opened upfront

Library name and version
Kros.KORM [3.6.3]

Describe the bug
BulkUpdate operation on IDbSet throws System.InvalidOperationException.

Steps To Reproduce

  1. Create Database with ConnectionStringSettings object or connectionString + adoClientName parameters.
  2. Via IDbSet change some data (dbSet.Edit(item)).
  3. Call IDbSet.BulkUpdate().
  4. Exception is thrown.

Error description:

System.InvalidOperationException: 'ExecuteNonQuery requires an open and available Connection. The connection's current state is closed.'

StackTrace:

at System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean async)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at Kros.Data.BulkActions.SqlServer.SqlServerBulkUpdate.CreateTempTable(IDataReader reader, String tempTableName)
at Kros.Data.BulkActions.BulkUpdateBase.CreateTempTable(IDataReader reader)
at Kros.Data.BulkActions.BulkUpdateBase.Update(IDataReader reader)
at Kros.Data.BulkActions.BulkUpdateBase.Update(IBulkActionDataReader reader)
at Kros.KORM.Query.DbSet.BulkUpdateCore(IEnumerable items, Action tempTableAction)
at Kros.KORM.Query.DbSet.BulkUpdate()

Expected behavior
BulkUpdate should execute without exception.

Actual behavior
IDbSet.BulkUpdate() throws exception.

Create reader for reading data from TXT file

  • Create reader which can read data from TXT, so it can be used for data materialization in KORM.
  • Create simplier interface IReader, as it is in BulkInsert.
  • Allow simply configuration (which index represents the property).

Async Await for Korm

Create support for async/await for updating data.

  • CommitChangesAsync
  • BulkInsertAsync
    • Utils
    • Korm
  • BulkUpdateAsync
    • Utils
    • Korm
  • Documentation

Support for translate LINQ Skip method to SQL

Breaking Changes

  • Arguments of QueryProvider's constructors has changed. Argument of type ISqlExpressionVisitor is now ISqlExpressionVisitorFactory. Default implementations are SqlServerSqlExpressionVisitorFactory and MsAccessSqlExpressionVisitorFactory.

Description

Linq method Take is actualy translated into SQL. But method Skip isn't.
Please support Skip method.

Common scenario:

using(var database = new Database("connection string ...", SqlServerDataHelper.ClientId)
{
  var people = database.Query<Person>().OrderBy(p=> p.Id).Skip(10).Take(10)
}

to be translated into:

SELECT Id, FirstName, ... FROM Person ORDER BY Id OFFSET 10 ROWS FETCH NEXT 10 ROWS ONLY

This syntax is available only in Ms SQL, so exception on MsAccess should be thrown.

Notes

  • This syntax is supported from SQL Server 2012. We need to support older versions too.
  • We need to support Microsoft Access.
  • Proposed solution is, when OFFSET/LIMIT is not supported out of the box, we will do it manually over returned data (IEnumerable<T>).
  • OFFSET is allowed only when ORDER BY is specified. If there is no ORDER BY, InvalidOperationException will be thrown.

BulkDelete

  • Deleted items will be in DbSet.EditedItems.
  • Items will be inserted by BulkInsert into temp table (be carefull about differences between MS SQL and MS Access, look at BulkInsert or BulkUpdate).
  • Then execute a query with join from temp table to source table.
  • This technique is significaly faster than executing query per item.

Add string.Format() extension methods

We can add Format() extension methods to string so we can use:

"some string".Format(arg1, arg2)

instead of
string.Format("some string", arg1, arg2)

It will be very convenient especially for formatted resource messages.

We probably should add all string.Format() overloads.

Master-Detail

  • Modify KORM, so it can read Master-detail.

Something like korm.Query<Person>().Include(p=>p.Addresses)

Use string interpolation to define query parameters

Support query writing with parameters using the FormattableString class.

So, when I use the korm.Query<Person>().Sql($"SELECT * FROM Person WHERE Id = {25}"), the parameters id will be converted into DbParameter parameter.

  • .Sql()
  • .Where()
  • .FirstOrDefault()
  • .Any()

Modify DbSet to not use CommandGenerator directly

  • Modify DbSet to not use CommandGenerator directly, but only IQueryProvider.
  • CommandGenerator is class for creating commands for DbSet. But in case of database connection, it relies on IQueryProvider. IQueryProvider creates instance of DbCommand, because it knows database connection. Because of that, there is useless method GetCommandForCurrentTransaction.
  • It would be great if the DbSet will be dependent only on IQueryProvider and IQueryProvider will use CommandGenerator inside. Consider deleting CommandGenerator and moving code to IQueryProvider.

NULL filtering in Query's Where condition with lambda expression

In my model I have nullable field like:
public int? PaymentId { get; set; }

Currently there is only one way to filter records from DB, where PaymentId field value == NULL - with use of string condition like this:
.Where("(PaymentId IS NULL) AND (UserId = @1)", userId)

Pls add support for query syntax with lambda expression.

Allow executing ExecuteStoredProcedure and ExecuteNonQuery in transaction

  • Current implementations of ExecuteNonQuery and ExecuteStoredProcedure use method QueryProvider.CreateCommand() for creating commands. The command is created directly from connection, not from TransactionHelper. Therefore commands do not know nothing about running or newly created transactions.
  • New implementations of ExecuteNonQuery and ExecuteStoredProcedure should use command created by TransactionHelper, to execute them in proper transaction.

Make string "System.Data.SqlClient" a constant

We use string "System.Data.SqlClient" as key in several places. We should make it a public constant somewhere and use this constant instead.

To match Kros.Utils.MsAccess, add Kros.Utils.SqlServer.SqlServerDataHelper.ClientId.

Fluent SQL DDL statements

DDL should contains:

  • CREATE TABLE : Columns, Primary Key, Indexes, Foreign keys.

  • DROP TABLE

  • ALTER TABLE : Add/Delete/Modify/Rename columns.

  • CREATE INDEX : Type, Columns, Clustered

  • DROP INDEX

  • CREATE FOREIGN KEY : Columns, Delete/Update rule.

  • DROP FOREIGN KEY

  • Executing will be on demand, like as Linq.

Create API (Interface) for logging

  • In Kros.Utils will be only interface without implementation. Those implementations will be in separate libraries.

API should satisfy:

  • Has to be compatible with logging in .NET Core.
  • Use extisting system (Serilog, NLog...).
  • Logging in code is persistent. Whether the log is saved (or written) is defined by configuration.
  • Logging is modified via configuration, out of application, without precompiling code.
  • Logging should be as fast as possible. If logs are written somewhere, slowing is expected.

Think about exception messages

  • Class WinApiHelpers throws exception with slovak message.
  • Consider what to do with them. (localized resources or not, etc.)
  • Issue concerns every repository.

Create factory for BulkInsert

  • If you want to use BulkInsert, you have to choose between MsAccessBulkInsert or SqlServerBulkInsert based on current execution.
  • Create factory, which will provide "correct" BulkInsert.

Quick start wiki for KORM

It would be great to have a quick start tutorial for working with KORM.

What should include:

  1. Script for creating table
  2. Define entity
    • Primary key with autoincrement
    • NoMap column
    • Service injection
    • Converter
  3. Adding entities
  4. Querying data
  5. Editing entities
  6. Deleting entities
  7. In each section will be a reference to detail in readme or documentation page.

KORM throws ArgumentException when CommitChanges is call

When we call the CommitChanges and there are no changes to the addition, KORM throws ArgumentException.

Error message:

System.ArgumentException : Hodnota parametra musí byť väčšia ako 0, ale skutočná hodnota je 0.
Parameter name: batchSize

Error stack trace:

at Kros.Utils.Check.GreaterThan[T](T param, T value, String paramName) in C:\projects\kros-libs-u2wo6\Kros.Utils\src\Kros.Utils\Utils\Check.cs:line 472
   at Kros.Data.IdGeneratorBase..ctor(String tableName, Int32 batchSize) in C:\projects\kros-libs-u2wo6\Kros.Utils\src\Kros.Utils\Data\IdGeneratorBase.cs:line 86
   at Kros.Data.SqlServer.SqlServerIdGeneratorFactory.GetGenerator(String tableName, Int32 batchSize) in C:\projects\kros-libs-u2wo6\Kros.Utils\src\Kros.Utils\Data\SqlServer\SqlServerIdGeneratorFactory.cs:line 45
   at Kros.KORM.Query.QueryProvider.CreateIdGenerator(String tableName, Int32 batchSize) in C:\projects\kros-libs-u2wo6\Kros.KORM\src\Kros.KORM\Query\Providers\QueryProvider.cs:line 449
   at Kros.KORM.Query.DbSet`1.GeneratePrimaryKeys(HashSet`1 items) in C:\projects\kros-libs-u2wo6\Kros.KORM\src\Kros.KORM\Query\DbSet.cs:line 297
   at Kros.KORM.Query.DbSet`1.CommitChangesAddedItems(HashSet`1 items) in C:\projects\kros-libs-u2wo6\Kros.KORM\src\Kros.KORM\Query\DbSet.cs:line 279
   at Kros.KORM.Query.DbSet`1.<CommitChanges>b__21_0() in C:\projects\kros-libs-u2wo6\Kros.KORM\src\Kros.KORM\Query\DbSet.cs:line 246
   at Kros.KORM.Query.QueryProvider.ExecuteInTransaction(Action action) in C:\projects\kros-libs-u2wo6\Kros.KORM\src\Kros.KORM\Query\Providers\QueryProvider.cs:line 250
   at Kros.KORM.UnitTests.Integration.DbSetShould.UpdateData() in C:\projects\kros-libs-u2wo6\Kros.KORM\tests\Kros.KORM.UnitTests\Integration\DbSetShould.cs:line 103

Generate queries with columns in parentheses

  • Consider entity with property Order and also the same column in the database. KORM will generate query like : SELECT Col1, Col2, Order, Col3 FROM Table. This query will not be executed, because Order is reserved keyword.
  • All columns in query need to be closed in parentheses. If someone writes whole query on its own, query shoud be write correctly (with parentheses).

Init IdGenerator table and stored procedure directly by KORM

It would be great if we could initialize the necessary stuff for the generator directly by calling the method above Kros.Korm.Database.

For example:

using(var database = new Database("connection string ...", "System.Data.SqlClient")
{
  database.CheckAndCreateIdGeneratorTable();
}

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.