Dapper .NET: problems with struct parameterized queries - c#

I am trying to use structs as parameters in Dapper queries. It does not work for me. But it seems like it should work.
A failing example:
struct Simple { public int ID; }
[TestMethod]
public void StructParameter()
{
int result = Db.Query<int>("select [ID] = #ID", new Simple { ID = 123 }).First();
result.Should().Be(123);
}
A working example:
[TestMethod]
public void AnonymousParameter()
{
int result = Db.Query<int>("select [ID] = #ID", new { ID = 123 }).First();
result.Should().Be(123);
}
The error thrown in the first case:
System.Data.SqlClient.SqlException: Must declare the scalar variable "#ID".
Result StackTrace:
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
at Dapper.SqlMapper.<QueryImpl>d__11`1.MoveNext() in d:\Dev\dapper-dot-net\Dapper NET40\SqlMapper.cs:line 1553
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Dapper.SqlMapper.Query[T](IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable`1 commandTimeout, Nullable`1 commandType) in d:\Dev\dapper-dot-net\Dapper NET40\SqlMapper.cs:line 1443
...
I am using Dapper version 1.38.
Per suggestion by Dirk, property instead of a filed works just fine:
struct Simple {
public int ID { get; set; }
}

The problem is not caused by using structs, it's caused by using fields instead of properties.
If you'd change struct Simple into class Simple is still wouldn't work because the parameter reader creates only IL code to read properties.
Changing the ID field into a property will solve it.

Related

C# call to MS-SQL stored procedure not receiving parameters [duplicate]

This question already has an answer here:
Error With SqlCommand not accepting Parameter Arguments
(1 answer)
Closed 6 months ago.
The following image is the code used to call MS=SQL stored procedure, as you can see, I am attempting to provide parameters in the request
using (SqlConnection connection = new SqlConnection(sqlAuth)) {
// Open database connectionS
connection.Open();
// Call upon stored procedure
SqlCommand cmd = new SqlCommand("InsertSystem", connection);
cmd.Parameters.Add("#ObjectID", SqlDbType.VarChar).Value = Request.Form["objectid"].ToString();
cmd.Parameters.Add("#SystemID", SqlDbType.VarChar).Value = Request.Form["systemid"].ToString();
cmd.Parameters.Add("#ItemID", SqlDbType.Int).Value = Request.Form["itemid"].ToString();
int records = cmd.ExecuteNonQuery();
// Close database connection
connection.Close();
}
message = "Record Saved<br /><br />";
The error which is returned from this is as follows:
System.Data.SqlClient.SqlException
HResult=0x80131904
Message=Procedure or function 'InsertSystem' expects parameter '#SystemID', which was not supplied.
Source=Core .Net SqlClient Data Provider
StackTrace:
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite, String method)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite, String methodName)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at ServiceObjectsWebApp.Pages.ObjectInsertModel.OnPost() in C:\Users\rmcd\Desktop\ServiceObecjts\ServiceObjectsWebApp\Pages\ObjectInsert.cshtml.cs:line 46
at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.ExecutorFactory.VoidHandlerMethod.Execute(Object receiver, Object[] arguments)
at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.<InvokeHandlerMethodAsync>d__29.MoveNext()
This exception was originally thrown at this call stack:
[External Code]
ServiceObjectsWebApp.Pages.ObjectInsertModel.OnPost() in ObjectInsert.cshtml.cs
[External Code]
You're calling a stored procedure so you need to tell it that:
cmd.CommandType = CommandType.StoredProcedure;

Cannot create database using Dapper and database name passed in as # variable, why?

I have a code to create database with dapper:
public static bool CreateDatabase(string connectionString, string databaseName)
{
const string DATABASE_CREATE_QUERY = "CREATE DATABASE (#databaseName)";
using (var connection = new SqlConnection(connectionString))
{
var affectedRows = connection.Execute(DATABASE_CREATE_QUERY, new { databaseName });
return affectedRows > 0 ? true : false;
}
}
CreateDatabase("Server=10.10.10.10;User ID=user;Password=password;MultipleActiveResultSets=true;", "TEST_DB");
Every time I run this method, I get an error:
Incorrect syntax near '('.
With trace:
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at Dapper.SqlMapper.ExecuteCommand(IDbConnection cnn, CommandDefinition& command, Action`2 paramReader) in E:\GitHub\Dapper\Dapper\SqlMapper.cs:line 2827
at Dapper.SqlMapper.ExecuteImpl(IDbConnection cnn, CommandDefinition& command) in E:\GitHub\Dapper\Dapper\SqlMapper.cs:line 570
at Dapper.SqlMapper.Execute(IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Nullable`1 commandTimeout, Nullable`1 commandType) in E:\GitHub\Dapper\Dapper\SqlMapper.cs:line 443
at DbCreator.DbUtils.CreateDatabase(String connectionString, String databaseName) in E:\src_projects\DbCreator\DbUtils.cs:line 48
at DbCreator.***.Run(String connectionString) in E:\src_projects\DbCreator\***.cs:line 23
If I set the query the ugly way
const string DATABASE_CREATE_QUERY = $"CREATE DATABASE {databaseName}";
and run
connection.Execute(DATABASE_CREATE_QUERY);
it all works fine.
If I don't use the brackets () in the QUERY
const string DATABASE_CREATE_QUERY = "CREATE DATABASE #databaseName";
I get an error:
Incorrect syntax near '#databaseName'
I have also tried methods ExecuteScalar, Query, but with the same result.
Any ideas why this wont work the Dapper way?
This is because sp_executesql is being used for parameterizing.This is what is being executed in the database via Dapper interpretation;
exec sp_executesql N'Create Database (#DBName)',N'#DBName nvarchar(4000)',#DBName=N'Test'
See why that wont work with sp_executesql: Table name as variable
Your best bet would be to either create a stored procedure, or use the approach of string replacement.
Because create database statement doesn't require ().
Try :
const string DATABASE_CREATE_QUERY = "CREATE DATABASE #databaseName";

Webmatrix QueryValue call raising SQLException "Incorrect syntax near '0'."

The following method looks up an Id for an IMEI code
public static int GetId(string imei)
{
int returnVal = 0;
string sqlGetVehicle = "sp_Scalar_VehicleId_For_IMEI #IMEI = {0}";
using (var db = Database.Open("ClientApp"))
{
returnVal = db.QueryValue(sqlGetVehicle, imei);
}
return returnVal;
}
The sp it calls is set to return a single value. When run in SMO the procedure works fine. Give it an IMEI string, and if it's in the table it will return the vehicleId. If it isn't, it returns a 0.
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: *trim*
-- Create date: 2017-05-12
-- Description: Returns the VehicleId Associated with an IMEI
-- =============================================
ALTER PROCEDURE [dbo].[sp_Scalar_VehicleId_For_IMEI]
#IMEI varchar(20)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE #VehicleId int
SELECT #VehicleId = v.VehicleId
FROM Vehicles v
WHERE v.TabletIMEI = #IMEI
-- ISNULL() in query wasn't working
IF #VehicleId IS NULL
BEGIN
SET #VehicleId = 0
END
SELECT #VehicleId
END
When run from code, the procedure throws System.Data.SqlClient.SqlException: Incorrect syntax near '0'. It was throwing this before I removed the ISNULL() check, and after I replaced it with the IF statement. What is the root cause of this error?
[SqlException (0x80131904): Incorrect syntax near '0'.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +2442126
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +5736904
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +628
System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +3731
System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() +58
System.Data.SqlClient.SqlDataReader.get_MetaData() +89
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +379
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds, Boolean describeParameterEncryptionRequest) +2026
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite) +375
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +53
System.Data.SqlClient.SqlCommand.ExecuteScalar() +271
WebMatrix.Data.Database.QueryValue(String commandText, Object[] args) +111
*trim*.Forms.*trim*.Vehicle.GetId(String imei) in C:\Users\*trim*\Documents\Visual Studio 2017\WebSites\*trim*\App_Code\Vehicle.cs:258
ASP.Functions.UpdateSessionVehicle() in C:\Users\*trim*\Documents\Visual Studio 2017\WebSites\*trim*\App_Code\Functions.cshtml:148
ASP._Page_Default_cshtml.Execute() in C:\Users\*trim*\Documents\Visual Studio 2017\WebSites\*trim*\Default.cshtml:8
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +198
System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1 executors) +69
System.Web.WebPages.WebPage.ExecutePageHierarchy() +131
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +78
System.Web.WebPages.WebPageHttpHandler.ProcessRequestInternal(HttpContextBase httpContext) +116
The placeholder for Webmatrix seems to be #0 instead of {0}. Also, to actually execute a stored procedure, it should be called with "Exec".
With that in mind, the command text should be defined as:
string sqlGetVehicle = "Exec sp_Scalar_VehicleId_For_IMEI #IMEI = #0";
According to this post another way could be:
returnVal = db.Query("Exec sp_Scalar_VehicleId_For_IMEI", imei);

_entities.SaveChange() error

I'm working on an intranet, the user can create a new Employee that contains his information (Name, Login, Password etc.) with the following :
if (_service.Create(objEmployee))
{
WebSecurity.CreateUserAndAccount(objEmployee.Login, objEmployee.Password); // Creates the account as we create the Employee (form authentication)
return new RedirectResult(Url.Action("Index"));
}
Once it enters Create and checks the information, it has to save it all with :
public Employee Create(Employee objEmployee)
{
_entities.AddToEmployees(objEmployee);
_entities.SaveChanges(); // Fails here
return objEmployee;
}
And I get the following error :
An error occurred while updating the entries. See the inner exception for details.
objEmployee contains all the information about the Employee and I can't figure why the saving fails. (And how to access the inner exception)
Here's the information I found :
System.Data.UpdateException was caught
HResult=-2146233087
Message=An error occurred while updating the entries. See the inner exception for details.
Source=System.Data.Entity
StackTrace:
at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
at System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache)
at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options)
at System.Data.Objects.ObjectContext.SaveChanges()
at CRAWebSiteMVC.Models.EntityEmployeeManagerRepository.Create(Employee objEmployee) in c:\Users\kade\Source\Workspaces\InfoCubedProjects\CRA\CRAWebSiteMVC\Models\Employee\EntityEmployeeManagerRepository.cs:line 17
at CRAWebSiteMVC.Models.EmployeeManagerService.Create(Employee objEmployee) in c:\Users\kade\Source\Workspaces\InfoCubedProjects\CRA\CRAWebSiteMVC\Models\Employee\EmployeeManagerService.cs:line 79
InnerException: System.Data.SqlClient.SqlException
HResult=-2146232060
Message=Cannot insert the value NULL into column 'Password', table 'CRAV34.dbo.Employee'; column does not allow nulls. INSERT fails.
The statement has been terminated.
Source=.Net SqlClient Data Provider
ErrorCode=-2146232060
Class=16
LineNumber=1
Number=515
Procedure=""
Server=MMSDEVNEW\SQL2008
State=2
StackTrace:
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator translator, EntityConnection connection, Dictionary`2 identifierValues, List`1 generatedValues)
at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
InnerException:
Please note that this is the model for Password :
public partial class Employee
{
public global::System.String Password
{
get
{
return _Password;
}
set
{
OnPasswordChanging(value);
ReportPropertyChanging("Password");
_Password = StructuralObject.SetValidValue(value, false);
ReportPropertyChanged("Password");
OnPasswordChanged();
}
}
private global::System.String _Password;
partial void OnPasswordChanging(global::System.String value);
partial void OnPasswordChanged();
}
Since the model created by Entity Framework was partial, I decided to create another partial class with the same name containing Password.

dapper Error converting data type datetime to smalldatetime when executing stored procedure

I have a table in my database with smalldatetime type. And I have a stored procedure that updates data in that table.
The stored procedure gets a #LastLogin smalldatetime parameter with the date to update.
In c# I have a code that calls the stored procedure using dapper:
loginDetails.LastLoginDate = (DateTime)System.Data.SqlTypes.SqlDateTime.MinValue;
db.Execute("stp_UpdateLogin", loginDetails, commandType: CommandType.StoredProcedure);
When I run this I get the following error:
System.Data.SqlClient.SqlException (0x80131904): Error converting data type datetime to smalldatetime.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at Dapper.SqlMapper.ExecuteCommand(IDbConnection cnn, CommandDefinition& command, Action`2 paramReader) in d:\Dev\dapper-dot-net\Dapper NET40\SqlMapper.cs:line 3310
at Dapper.SqlMapper.ExecuteImpl(IDbConnection cnn, CommandDefinition& command) in d:\Dev\dapper-dot-net\Dapper NET40\SqlMapper.cs:line 1310
at Dapper.SqlMapper.Execute(IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Nullable`1 commandTimeout, Nullable`1 commandType) in d:\Dev\dapper-dot-net\Dapper NET40\SqlMapper.cs:line 1185
at Memoriez.Repositories.UsersRepository.UpdateUser(User user) in f:\Development\Memoriez\Memoriez.Repositories\UsersRepository.cs:line 58
ClientConnectionId:02cae914-507b-4c21-9799-8ec0940fc3d9
How can I make sure that dapper passes what SQL expects?
That's because
(DateTime)System.Data.SqlTypes.SqlDateTime.MinValue = 1/1/1753 12:00:00 AM
While the minimum value for
SMALLDATETIME = 1900-01-01 00:00:00
You could create a helper class:
public static class SqlSmallDateTime
{
public static readonly SqlDateTime MinValue = new SqlDateTime(new DateTime(1900, 01, 01, 00, 00, 00));
}

Categories

Resources