EF Record and play use: Recording user sql when a bug occurred (part 4 of 5)

 

Part 1 : What is EF record and play : http://msprogrammer.serviciipeweb.ro/2014/11/29/entity-framework-6-record-and-play-1-of-5/ 

Part 2: EF Record and play use: Testing : http://msprogrammer.serviciipeweb.ro/2014/12/08/entity-framework-6-record-and-play-use-unit-testing-part-2-of-5/

Part 3: EF Record and play use: Make demo: http://msprogrammer.serviciipeweb.ro/2014/12/14/entity-framework-6-record-and-play-use-making-demos-part-3-of-5/ 

Part 4: EF Record and play use: Record user Sql when a bug occurs: http://msprogrammer.serviciipeweb.ro/2014/12/26/ef-record-and-play-use-recording-user-sql-when-a-bug-occurred-part-4-of-5/

Part 5: EF record and play: conclusions: http://msprogrammer.serviciipeweb.ro/2015/01/05/ef-record-and-play-conclusions/

 

In this video tutorial I will show how to see the sql when a database bug occurs.

Let’s suppose that a department should have the name not null – and , by mistake, we have not prevented the registering of a null in the name of the department

We put those lines

 
 #region set record EF
            record = new InterceptionRecordOrPlay(@"DemoEmployeeAndDepartment.zip", ModeInterception.Record);

            DbInterception.Add(record);
            #endregion 

We register the null name department and  in the DemoEmployeeAndDepartment.zip we see the error

<?xml version="1.0"?>
<InterceptionData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <CommandText>INSERT [Department]([NameDepartment])
VALUES (NULL)
; SELECT [Id]
FROM [Department]
WHERE [Id] = CAST (@@IDENTITY AS int)</CommandText>
  <NonQuery>0</NonQuery>
  <ThrownExc>
    <ExceptionType>System.Data.SqlServerCe.SqlCeException</ExceptionType>
    <ExceptionMessage>The column cannot contain null values. [ Column name = NameDepartment,Table name = Department ]</ExceptionMessage>
  </ThrownExc>
</InterceptionData>

Source code is available at https://github.com/ignatandrei/EFRecordAndPlay/wiki/
There is also a NuGet package at https://www.nuget.org/packages/EFRecordAndPlay/