Skip to content

Commit 0821cb8

Browse files
committed
Add failing test for Delete with a where clause evaluating to false
The Delete method fails with a `System.Data.SqlClient.SqlException` when the where clause evaluates to false. Obviously, it would be better not to call the Delete method at all if the expression is known to evaluate to false but I think it should not fail nonetheless. I would love to propose a solution to this issue but unfortunately, I'm not yet familiar enough with LINQ to Entities.
1 parent 8d1bdad commit 0821cb8

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Description: Entity Framework Bulk Operations & Utilities (EF Bulk SaveChanges, Insert, Update, Delete, Merge | LINQ Query Cache, Deferred, Filter, IncludeFilter, IncludeOptimize | Audit)
2+
// Website & Documentation: https://github.com/zzzprojects/Entity-Framework-Plus
3+
// Forum & Issues: https://github.com/zzzprojects/EntityFramework-Plus/issues
4+
// License: https://github.com/zzzprojects/EntityFramework-Plus/blob/master/LICENSE
5+
// More projects: http://www.zzzprojects.com/
6+
// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved.
7+
8+
using System.Linq;
9+
using Microsoft.VisualStudio.TestTools.UnitTesting;
10+
using Z.EntityFramework.Plus;
11+
12+
namespace Z.Test.EntityFramework.Plus
13+
{
14+
public partial class BatchDelete_WhereValue
15+
{
16+
[TestMethod]
17+
public void False()
18+
{
19+
TestContext.DeleteAll(x => x.Entity_Basics);
20+
TestContext.Insert(x => x.Entity_Basics, 50);
21+
22+
using (var ctx = new TestContext())
23+
{
24+
// BEFORE
25+
Assert.AreEqual(1225, ctx.Entity_Basics.Sum(x => x.ColumnInt));
26+
27+
// ACTION
28+
var rowsAffected = ctx.Entity_Basics.Where(x => false).Delete();
29+
30+
// AFTER
31+
Assert.AreEqual(1225, ctx.Entity_Basics.Sum(x => x.ColumnInt));
32+
Assert.AreEqual(0, rowsAffected);
33+
}
34+
}
35+
}
36+
}

src/test/Z.Test.EntityFramework.Plus.EF6/Z.Test.EntityFramework.Plus.EF6.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@
157157
<Compile Include="BatchDelete\InMemory\Twenty.cs" />
158158
<Compile Include="BatchDelete\PrimaryKey\Single.cs" />
159159
<Compile Include="BatchDelete\PrimaryKey\Many.cs" />
160+
<Compile Include="BatchDelete\WhereValue\False.cs" />
160161
<Compile Include="BatchDelete\WhereValue\Many_Constant.cs" />
161162
<Compile Include="BatchDelete\WhereValue\Many_Variable.cs" />
162163
<Compile Include="BatchDelete\WhereValue\Single_Constant.cs" />

0 commit comments

Comments
 (0)