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

Commit ffda2d5

Browse files
committed
Add API to return quoted first matching field
1 parent bf5907d commit ffda2d5

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/ServiceStack.OrmLite/Expressions/SqlExpression.Join.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,5 +235,29 @@ public virtual SqlExpression<T> Or<Source, Target>(Expression<Func<Source, Targe
235235
AppendToWhere("OR", predicate);
236236
return this;
237237
}
238+
239+
public string QuoteFirstField(string fieldName)
240+
{
241+
foreach (var tableDef in tableDefs)
242+
{
243+
var firstField = tableDef.FieldDefinitions.FirstOrDefault(x => x.Name == fieldName);
244+
if (firstField != null)
245+
{
246+
return DialectProvider.GetQuotedColumnName(tableDef, firstField);
247+
}
248+
}
249+
//Fallback to {Table}{Field} property convention
250+
foreach (var tableDef in tableDefs)
251+
{
252+
var firstField = tableDef.FieldDefinitions.FirstOrDefault(x =>
253+
tableDef.Name + x.Name == fieldName);
254+
255+
if (firstField != null)
256+
{
257+
return DialectProvider.GetQuotedColumnName(tableDef, firstField) + " as " + fieldName;
258+
}
259+
}
260+
return null;
261+
}
238262
}
239263
}

0 commit comments

Comments
 (0)