Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Commit c393713

Browse files
Tony Mackayoysteinkrog
authored andcommitted
Added the ability to Delete records using a predicate.
Removed the Delete function from DeleteExtensions extension method into the SQLite.cs file. (cherry picked from commit b783fe7) Conflicts: src/SQLite.cs tests/SQLite.Tests.csproj
1 parent 1a4f5fa commit c393713

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

src/SQLite.Net/TableQuery.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,27 @@ public TableQuery<T> Take(int n)
131131
return q;
132132
}
133133

134+
public int Delete(Expression<Func<T, bool>> predExpr)
135+
{
136+
if (predExpr.NodeType == ExpressionType.Lambda)
137+
{
138+
var lambda = (LambdaExpression) predExpr;
139+
var pred = lambda.Body;
140+
var args = new List<object>();
141+
var w = CompileExpr(pred, args);
142+
var cmdText = "delete from \"" + Table.TableName + "\"";
143+
cmdText += " where " + w.CommandText;
144+
var command = Connection.CreateCommand(cmdText, args.ToArray());
145+
146+
var result = command.ExecuteNonQuery();
147+
return result;
148+
}
149+
else
150+
{
151+
throw new NotSupportedException("Must be a predicate");
152+
}
153+
}
154+
134155
[PublicAPI]
135156
public TableQuery<T> Skip(int n)
136157
{

0 commit comments

Comments
 (0)