Code Monkey home page Code Monkey logo

dev.data's People

Contributors

aclerbois avatar becold avatar dvoituron avatar vpellichero avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

dev.data's Issues

cmd.ExecuteTable<(Tuple)> does not map correctly columns data to tuple.

Hello Denis :-)

I found out the cmd.ExecuteTable<(Tuple)> does not map correctly columns data to tuple.
On version 4.1.1

Example C# code:

using (var cmd = GetDatabaseCommand())
{
    cmd.TagWith("MyTag");
    cmd.CommandText = "SELECT [Id], [FirstName] FROM [Users]";
    var result = cmd.ExecuteTable<(int Id, string FirstName)>();
    System.Diagnostics.Debug.Assert(result.Count() == 1); // 1 user found: Ok
    System.Diagnostics.Debug.Assert(result.First().Id == 1); // Id is not the one expected: The assertion fails
}

Crash when generating entities with DECIMAL (1,1) SQL type

Hello,

Following method from DataColumn.cs yields a possible null reference if you have, for example, a DECIMAL(1,1) SQL datatype when you want to generate entities with the "Range" annotation. I know this should not occur as DECIMAL(1,1) does not make a lot of sense, but it can occur and it lets the user only with a red message "Object reference not set to an instance of an object".

        /// <summary>
        /// Gets the min/max value, based on Precision and Scale.
        /// </summary>
        /// <returns></returns>
        public Tuple<string, string> GetMinMax()
        {
            // Ex. 1234.56 => Precision = 6  ;  Scale = 2

            const string NINES = "9999999999999999999999999999999999999999";

            if (Precision != null && Scale != null &&
                Precision > 0 && Precision <= 38 &&
                Scale >= 0 && Scale <= 38 &&
                Precision > Scale)
            {
                string leftPart = NINES.Substring(0, Precision.Value - Scale.Value);
                string rightPart = Scale.Value > 0 ? NINES.Substring(0, Scale.Value) : "0";
                return new Tuple<string, string>($"-{leftPart}.{rightPart}", $"{leftPart}.{rightPart}");
            }
            else
            {
                return null;
            }
        }

crash occur because of these two lines

 var minMax = column.GetMinMax();
 code.AppendLine($"        [Range({minMax.Item1}d, {minMax.Item2}d)]");

in file Generator.Csharp.cs at line 109.

Change request : limit set of columns in 'MapTo'

Could it be interesting to overload the function MapTo in a way to limit the set of columns it will access by reflection ?

At the moment, if i want to bind properties of an object MyObject like dataRow.MapTo<MyObject>() it will look for and bind all instance and public properties of MyObject as far as i understand.

What if we had a method MapTo<MyObject>(propertyNames) where propertyNames could be an IEnumerable<string>.
This would be useful if i need to bind only a subset of my properties.

Regards,

Alexandre

"Sequence contains no matching element" using GenerateEntities on Oracle DB

Using the following command

DbCmd GenerateEntities -cs="MY_CORRECTLY_FORMATTED_CONNECTION_STRING" --provider=Oracle --Namespace="MySolution.MyProject.Model" --NullableRefTypes --SortProperties

Yields an error "Sequence contains no matching element".

Similar issues have been reported using EntityFramework (see https://stackoverflow.com/questions/22982749/sequence-contains-no-matching-element-entityframework). It could be a name issue for column types.

Could you please check this ?

DBMocker - AddRow

It is impossible to specified a type when adding row/columns to the DBMocker. It is annoying when we want to add a null value of any type in the first row. It will throw an exception when adding a second row with a correct value.

Example :
_connection.Mocks .When(cmd => cmd.CommandText.Contains("SELECT")) .ReturnsTable(MockTable .WithColumns("Tenure_StartDate") .AddRow(null) .AddRow(DateTime.Now));

To avoid that exception we need to add dummy data to force the tool to know the data type :
_connection.Mocks .When(cmd => cmd.CommandText.Contains("SELECT")) .ReturnsTable(MockTable .WithColumns("Tenure_StartDate") .AddRow(DateTime.Now) .AddRow(null) .AddRow(DateTime.Now));

DbCmd GenerateEntities: "Object reference not set to an instance of an object"

Hi,

I would like to generate my entities with the Range data annotation and for that, I am using this (simplified) command on my db:
DbCmd GenerateEntities -cs="Server=(localdb)\MyServer;Database=MyDatabase;" --provider=SqlServer --Namespace="MyProject.MyPackage.Entities" --Validations=Range

But sadly, I got this error message : "Object reference not set to an instance of an object."

I am using the lastest version (4.3.0.1).

Could you check this please ?
Thanks.

Get a formatted SQL including variables

Add a new method or update the existing method to get a formatted SQL command, with variables (query parameters) defined in top of this query.

So, you can copy/paste this query and execute it without changes.

Possible Optimization : use a Dictionary in DataRowConvertor 'ToType' function

In the following code from DataRowConvertor.cs

                var properties = rowType.GetProperties(BindingFlags.Public | BindingFlags.Instance);
                var newItem = Activator.CreateInstance<T>();

                foreach (var column in row.Table.Columns)
                {
                    var name = column.ColumnName;
                    var property = properties.GetFirstOrDefaultWithAttributeOrName(name);
                    if (property != null)
                    {
                        var value = row[name];
                        property.SetValue(newItem, value == DBNull.Value ? null : value, null);
                    }
                }

                return (T)Convert.ChangeType(newItem, typeof(T));

Could it be interesting to use a Dictionary or some other data structure that will improve performance instead of calling GetFirstOrDefaultWithAttributeOrName(name) for each property name ?

Regards,

Alexandre

DbConnection must be read from DbTransaction.Connection

Why to use DatabaseCommand(DbConnection, DbTransaction) ?
The first argument must be read from DbTransaction.Connection property.
And a problem can raised if the developer use a connection and a transaction from another connection.

Add Run command for the DbCmd tool

For the Generator.Tools (DbCmd), add a command Run to execute a specified SQL script or to execute all SQL files in the current directory (using minimatch format).

Examples:

DbCmd Run -cs="Server=.;Database=Scott" -query="UPDATE Config SET Value='1.0' WHERE Name='Version'"

DbCmd Run -cs="Server=.;Database=Scott" -file=MyScript.sql

DbCmd Run -cs="Server=.;Database=Scott" -files=**/*.sql

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.