-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
DeleteAMemberFromTheMembersTable.cs
51 lines (45 loc) · 1.68 KB
/
DeleteAMemberFromTheMembersTable.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using EFCorePgExercises.DataLayer;
using EFCorePgExercises.Utils;
using EFCorePgExercises.Entities;
using Microsoft.EntityFrameworkCore;
namespace EFCorePgExercises.Exercises.ModifyingData
{
[FullyQualifiedTestClass]
public class DeleteAMemberFromTheMembersTable
{
[FullyQualifiedTestMethod, Ignore]
public void Test_Method1()
{
// https://pgexercises.com/questions/updates/deletewh.html
// We want to remove member 37, who has never made a booking, from our database. How can we achieve that?
// delete from cd.members where memid = 37;
EFServiceProvider.RunInContext(context =>
{
var mem37 = context.Members.Where(x => x.MemId == 37).First();
context.Members.Remove(mem37);
context.SaveChanges();
});
}
[FullyQualifiedTestMethod, Ignore]
public void Test_Method2()
{
// https://pgexercises.com/questions/updates/deletewh.html
// We want to remove member 37, who has never made a booking, from our database. How can we achieve that?
// delete from cd.members where memid = 37;
EFServiceProvider.RunInContext(context =>
{
var entry = context.Entry(new Member { MemId = 37 });
entry.State = EntityState.Deleted;
context.SaveChanges();
/*
SET NOCOUNT ON;
DELETE FROM [Members]
WHERE [MemId] = @p0;
SELECT @@ROWCOUNT;
*/
});
}
}
}