Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 9f8f876

Browse files
committed
AddParameterForFieldToCommand override is not necessary to support datetime2.
Thanks @colinbreame for noticing it.
1 parent ffd434a commit 9f8f876

File tree

1 file changed

+2
-18
lines changed

1 file changed

+2
-18
lines changed

src/ServiceStack.OrmLite.SqlServer/SqlServerOrmLiteDialectProvider.cs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -150,25 +150,9 @@ public void UseDatetime2(bool shouldUseDatetime2)
150150
{
151151
_useDateTime2 = shouldUseDatetime2;
152152
DateTimeColumnDefinition = shouldUseDatetime2 ? "datetime2" : "datetime";
153-
InitColumnTypeMap();
153+
base.DbTypeMap.Set<DateTime>(shouldUseDatetime2 ? DbType.DateTime2 : DbType.DateTime, DateTimeColumnDefinition);
154+
base.DbTypeMap.Set<DateTime?>(shouldUseDatetime2 ? DbType.DateTime2 : DbType.DateTime, DateTimeColumnDefinition);
154155
}
155-
156-
protected override void AddParameterForFieldToCommand(IDbCommand command, FieldDefinition fieldDef, object objWithProperties)
157-
{
158-
//have to override, because DbTypeMap.Set<T> expects DbType, and SqlDbType is not a DbType...
159-
if(_useDateTime2 && (fieldDef.FieldType == typeof(DateTime) || fieldDef.FieldType == typeof(DateTime?))) {
160-
var sqlCmd = (SqlCommand)command;//should be SqlCommand...
161-
var p = sqlCmd.CreateParameter();
162-
p.ParameterName = string.Format("{0}{1}", ParamString, fieldDef.FieldName);
163-
164-
p.SqlDbType = SqlDbType.DateTime2;
165-
p.Value = GetValueOrDbNull(fieldDef, objWithProperties);
166-
167-
command.Parameters.Add(p);
168-
} else {
169-
base.AddParameterForFieldToCommand(command, fieldDef, objWithProperties);
170-
}
171-
}
172156

173157
public override long GetLastInsertId(IDbCommand dbCmd)
174158
{

0 commit comments

Comments
 (0)