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

Commit 0152f06

Browse files
committed
remove useless backing property and IList interfaces
1 parent 2c0259c commit 0152f06

File tree

2 files changed

+58
-47
lines changed

2 files changed

+58
-47
lines changed

src/ServiceStack.OrmLite/Expressions/IUntypedSqlExpression.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ public interface IUntypedSqlExpression : ISqlExpression
2525
string OrderByExpression { get; set; }
2626
int? Rows { get; set; }
2727
int? Offset { get; set; }
28-
IList<string> UpdateFields { get; set; }
29-
IList<string> InsertFields { get; set; }
28+
List<string> UpdateFields { get; set; }
29+
List<string> InsertFields { get; set; }
3030
ModelDefinition ModelDef { get; }
3131
IUntypedSqlExpression Clone();
3232

@@ -74,9 +74,9 @@ public interface IUntypedSqlExpression : ISqlExpression
7474
IUntypedSqlExpression Limit(int rows);
7575
IUntypedSqlExpression Limit();
7676
IUntypedSqlExpression ClearLimits();
77-
IUntypedSqlExpression Update(IList<string> updateFields);
77+
IUntypedSqlExpression Update(List<string> updateFields);
7878
IUntypedSqlExpression Update();
79-
IUntypedSqlExpression Insert(IList<string> insertFields);
79+
IUntypedSqlExpression Insert(List<string> insertFields);
8080
IUntypedSqlExpression Insert();
8181

8282
IDbDataParameter CreateParam(string name, object value = null, ParameterDirection direction = ParameterDirection.Input, DbType? dbType = null);
@@ -190,13 +190,13 @@ public int? Offset
190190
set { q.Offset = value; }
191191
}
192192

193-
public IList<string> UpdateFields
193+
public List<string> UpdateFields
194194
{
195195
get { return q.UpdateFields; }
196196
set { q.UpdateFields = value; }
197197
}
198198

199-
public IList<string> InsertFields
199+
public List<string> InsertFields
200200
{
201201
get { return q.InsertFields; }
202202
set { q.InsertFields = value; }
@@ -465,7 +465,7 @@ public IUntypedSqlExpression ClearLimits()
465465
return this;
466466
}
467467

468-
public IUntypedSqlExpression Update(IList<string> updateFields)
468+
public IUntypedSqlExpression Update(List<string> updateFields)
469469
{
470470
q.Update(updateFields);
471471
return this;
@@ -477,7 +477,7 @@ public IUntypedSqlExpression Update()
477477
return this;
478478
}
479479

480-
public IUntypedSqlExpression Insert(IList<string> insertFields)
480+
public IUntypedSqlExpression Insert(List<string> insertFields)
481481
{
482482
q.Insert(insertFields);
483483
return this;

src/ServiceStack.OrmLite/Expressions/SqlExpression.cs

Lines changed: 50 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Text;
88
using System.Collections.ObjectModel;
99
using System.Linq.Expressions;
10+
using System.Runtime.CompilerServices;
1011

1112
namespace ServiceStack.OrmLite
1213
{
@@ -21,8 +22,8 @@ public abstract partial class SqlExpression<T> : ISqlExpression, IHasUntypedSqlE
2122
private string havingExpression;
2223
private string orderBy = string.Empty;
2324

24-
IList<string> updateFields = new List<string>();
25-
IList<string> insertFields = new List<string>();
25+
public List<string> UpdateFields { get; set; }
26+
public List<string> InsertFields { get; set; }
2627

2728
private string sep = string.Empty;
2829
protected bool useFieldName = false;
@@ -41,9 +42,13 @@ protected string Sep
4142

4243
public SqlExpression(IOrmLiteDialectProvider dialectProvider)
4344
{
45+
UpdateFields = new List<string>();
46+
InsertFields = new List<string>();
47+
4448
modelDef = typeof(T).GetModelDefinition();
4549
PrefixFieldWithTableName = false;
4650
WhereStatementWithoutWhereString = false;
51+
4752
DialectProvider = dialectProvider;
4853
Params = new List<IDbDataParameter>();
4954
tableDefs.Add(modelDef);
@@ -66,8 +71,8 @@ protected virtual SqlExpression<T> CopyTo(SqlExpression<T> to)
6671
to.groupBy = groupBy;
6772
to.havingExpression = havingExpression;
6873
to.orderBy = orderBy;
69-
to.updateFields = updateFields;
70-
to.insertFields = insertFields;
74+
to.UpdateFields = UpdateFields;
75+
to.InsertFields = InsertFields;
7176
to.modelDef = modelDef;
7277
to.PrefixFieldWithTableName = PrefixFieldWithTableName;
7378
to.WhereStatementWithoutWhereString = WhereStatementWithoutWhereString;
@@ -662,9 +667,9 @@ public virtual SqlExpression<T> ClearLimits()
662667
/// <param name='updatefields'>
663668
/// IList<string> containing Names of properties to be updated
664669
/// </param>
665-
public virtual SqlExpression<T> Update(IList<string> updateFields)
670+
public virtual SqlExpression<T> Update(List<string> updateFields)
666671
{
667-
this.updateFields = updateFields;
672+
this.UpdateFields = updateFields;
668673
return this;
669674
}
670675

@@ -681,7 +686,7 @@ public virtual SqlExpression<T> Update<TKey>(Expression<Func<T, TKey>> fields)
681686
{
682687
sep = string.Empty;
683688
useFieldName = false;
684-
updateFields = Visit(fields).ToString().Split(',').ToList();
689+
UpdateFields = Visit(fields).ToString().Split(',').ToList();
685690
return this;
686691
}
687692

@@ -690,7 +695,7 @@ public virtual SqlExpression<T> Update<TKey>(Expression<Func<T, TKey>> fields)
690695
/// </summary>
691696
public virtual SqlExpression<T> Update()
692697
{
693-
this.updateFields = new List<string>();
698+
this.UpdateFields = new List<string>();
694699
return this;
695700
}
696701

@@ -707,7 +712,7 @@ public virtual SqlExpression<T> Insert<TKey>(Expression<Func<T, TKey>> fields)
707712
{
708713
sep = string.Empty;
709714
useFieldName = false;
710-
insertFields = Visit(fields).ToString().Split(',').ToList();
715+
InsertFields = Visit(fields).ToString().Split(',').ToList();
711716
return this;
712717
}
713718

@@ -717,9 +722,9 @@ public virtual SqlExpression<T> Insert<TKey>(Expression<Func<T, TKey>> fields)
717722
/// <param name='insertFields'>
718723
/// IList&lt;string&gt; containing Names of properties to be inserted
719724
/// </param>
720-
public virtual SqlExpression<T> Insert(IList<string> insertFields)
725+
public virtual SqlExpression<T> Insert(List<string> insertFields)
721726
{
722-
this.insertFields = insertFields;
727+
this.InsertFields = insertFields;
723728
return this;
724729
}
725730

@@ -728,7 +733,7 @@ public virtual SqlExpression<T> Insert(IList<string> insertFields)
728733
/// </summary>
729734
public virtual SqlExpression<T> Insert()
730735
{
731-
this.insertFields = new List<string>();
736+
this.InsertFields = new List<string>();
732737
return this;
733738
}
734739

@@ -901,30 +906,6 @@ public string OrderByExpression
901906
public int? Rows { get; set; }
902907
public int? Offset { get; set; }
903908

904-
public IList<string> UpdateFields
905-
{
906-
get
907-
{
908-
return updateFields;
909-
}
910-
set
911-
{
912-
updateFields = value;
913-
}
914-
}
915-
916-
public IList<string> InsertFields
917-
{
918-
get
919-
{
920-
return insertFields;
921-
}
922-
set
923-
{
924-
insertFields = value;
925-
}
926-
}
927-
928909
public ModelDefinition ModelDef
929910
{
930911
get
@@ -1733,6 +1714,10 @@ public IDbDataParameter CreateParam(string name,
17331714
p.Value = DialectProvider.GetParamValue(value, value.GetType());
17341715
DialectProvider.InitDbParam(p, value.GetType());
17351716
}
1717+
else
1718+
{
1719+
p.Value = DBNull.Value;
1720+
}
17361721

17371722
if (dbType != null)
17381723
p.DbType = dbType.Value;
@@ -1800,17 +1785,34 @@ public static IDbDataParameter CreateParam(this IDbConnection db,
18001785
string name,
18011786
object value=null,
18021787
DbType? dbType=null,
1803-
bool? isNullable=null,
18041788
byte? precision=null,
18051789
byte? scale=null,
18061790
int? size=null)
18071791
{
1808-
var dialectProvider = db.GetDialectProvider();
1792+
return db.GetDialectProvider().CreateParam(name, value, dbType, precision, scale, size);
1793+
}
18091794

1795+
public static IDbDataParameter CreateParam(this IOrmLiteDialectProvider dialectProvider,
1796+
string name,
1797+
object value = null,
1798+
DbType? dbType = null,
1799+
byte? precision = null,
1800+
byte? scale = null,
1801+
int? size = null)
1802+
{
18101803
var to = dialectProvider.CreateParam();
18111804

18121805
to.ParameterName = dialectProvider.GetParam(name);
1813-
to.Value = value;
1806+
1807+
if (value != null)
1808+
{
1809+
to.Value = dialectProvider.GetParamValue(value, value.GetType());
1810+
dialectProvider.InitDbParam(to, value.GetType());
1811+
}
1812+
else
1813+
{
1814+
to.Value = DBNull.Value;
1815+
}
18141816

18151817
var valueType = value != null ? value.GetType() : typeof(string);
18161818

@@ -1828,6 +1830,15 @@ public static IDbDataParameter CreateParam(this IDbConnection db,
18281830

18291831
return to;
18301832
}
1833+
1834+
public static IDbDataParameter AddParam(this IOrmLiteDialectProvider dialectProvider, IDbCommand dbCmd, object value)
1835+
{
1836+
var paramName = dbCmd.Parameters.Count.ToString();
1837+
1838+
var parameter = dialectProvider.CreateParam(paramName, value);
1839+
dbCmd.Parameters.Add(parameter);
1840+
return parameter;
1841+
}
18311842
}
18321843
}
18331844

0 commit comments

Comments
 (0)