apps72 / dev.data Goto Github PK
View Code? Open in Web Editor NEWThe Dev.Data.SqlDatabaseCommand is a set of components helping C# developers to execute SQL Queries and to retrieve data from SQL Server.
License: MIT License
The Dev.Data.SqlDatabaseCommand is a set of components helping C# developers to execute SQL Queries and to retrieve data from SQL Server.
License: MIT License
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
}
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.
The tool to convert data tables to C# classes converts a TinyInt to a sbyte. The correct type must be a byte.
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
To avoid confusion with AddParameter(T values), add a new method AddParameter(DbParameter parameter).
This code returns an exception
cmd.ExecuteTable(new
{
Param1 = new Nullable<int>()
Param2 = (int?)null
Param3 = (int?)4
});
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 ?
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));
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.
Allow a RetryExceptions process with the Core project.
To allow this feature with Oracle or SQLite database.
Hello,
nice library.
in order to use it with CRUD operations, how can we get the created identifier automatically created after insert command ?
and witch command to use? ExecuteNonQuery ?
thanks in advance
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.
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
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.
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.