question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enum causing issues

See original GitHub issue

Thanks for such a great library. It got me up and running in no time. However I have found that when C# class has Enum the change notifications doesn’t work. I am wondering if someone can please double check the issue. To reproduce the issue you can use the below code.

SQL table script:

CREATE TABLE [dbo].[TestResults](
	[TestResultId] [int] IDENTITY(1,1) NOT NULL,
	[JobId] [nvarchar](50) NULL,
	[BuildCode] [nvarchar](50) NULL,
	[CustomerSequenceNumber] [nvarchar](50) NULL,
	[TestStatus]  AS (case when ltrim(rtrim(isnull([ERRORMESSAGE],'')))='' then 'Pass' else 'Fail' end) PERSISTED NOT NULL,
	[ErrorMessage] [nvarchar](512) NULL,
	[TestDate] [datetime] NOT NULL,
	[TotalTimeInSeconds] [decimal](18, 2) NOT NULL,
	[StationId] [int] NOT NULL,
	[ShiftId] [int] NOT NULL,
	[RecipeId] [int] NULL,
	[DuplicateTestResult] [bit] NOT NULL,
 CONSTRAINT [PK_TestResults] PRIMARY KEY CLUSTERED 
(
	[TestResultId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[TestResults] ADD  CONSTRAINT [DF_TestResults_DuplicateTestResult]  DEFAULT ((0)) FOR [DuplicateTestResult]
GO

insert into TestResults
(
JobId
, BuildCode
, CustomerSequenceNumber
, ErrorMessage
, TestDate
, TotalTimeInSeconds
, StationId
, ShiftId
, RecipeId
, DuplicateTestResult
) values 
(
1441820	
, NULL	
, NULL	
, 'Random error'
, '2018-11-26 15:57:50'	
, 120	
, 2	
, 1
, 18	
, 0
)

and below C# code:

public partial class TestResult
{
   public int TestResultId { get; set; }
   public string JobId { get; set; }
   public string BuildCode { get; set; }
   public string CustomerSequenceNumber { get; set; }
   public TestStatus TestStatus { get; set; } //As long as this line is commented everything works
   public string ErrorMessage { get; set; }
   public DateTime TestDate { get; set; }
   public decimal TotalTimeInSeconds { get; set; }
   public int StationId { get; set; }
   public int ShiftId { get; set; }
   public int? RecipeId { get; set; }
   public bool DuplicateTestResult { get; set; }
}

public enum TestStatus
{
   None,
   Pass,
   Fail
}

internal class Program
{
   private static readonly string _connectionString = "Server=someserver;Initial Catalog=somedb;User id=uid;Password=password;MultipleActiveResultSets=True";
   private static void Main(string[] args)
   {
   	using (var dep = new SqlTableDependency<TestResult>(_connectionString, "TestResults"))
   	{
   		dep.OnChanged += Changed;
   		dep.OnError += Dep_OnError;
   		dep.Start();

   		Console.WriteLine("Press a key to exit");
   		Console.ReadKey();

   		dep.Stop();
   	}
   }

   private static void Dep_OnError(object sender, ErrorEventArgs e)
   {
   	Console.WriteLine(e.Error);
   }

   public static void Changed(object sender, RecordChangedEventArgs<TestResult> e)
   {
   	var changedEntity = e.Entity;
   	Console.WriteLine("DML operation: " + e.ChangeType + ", ID: " + changedEntity.TestResultId);
   }
}

I have checked the test cases including “EnumTestSqlServer.cs” file. The difference I noticed is that in this file enum is byte type so I am assuming the value stored in DB is number however in my case I am storing string DB (like “Pass”/“Fail”) and since I am using EF Core it takes care of converting string to enum.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
christiandelbiancocommented, Dec 9, 2018

Hi You must use 8.5.2. This version has been just Released. Regards

0reactions
christiandelbiancocommented, Dec 9, 2018

Enjoy

Read more comments on GitHub >

github_iconTop Results From Across the Web

What's up with all the enum hate lately? : r/typescript
Enums have pitfalls that can cause bugs VS union types and "object as const" which behave as expected. Not clear enough? I don't...
Read more >
The trouble with TypeScript enums
If you're not, I'll point out where the trouble with enums can be particularly pervasive and lead to uncaught runtime errors.
Read more >
Why are there compile errors when accessing an Enum ...
It looks like you defined the Enum as an inner class of another class. If you're doing this, you need to access it...
Read more >
The Trouble With Enums
Java's enums have been around for a while, and it's no surprise that you might run into trouble as new features have been...
Read more >
Re-order or delete enum entries, will it causes problems?
Yes, it's true. The issue here is that an enum type is just a glorified integer with predefined constants, nothing more. So a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found