SogdianWarrior
SogdianWarrior
CC#
Created by baristaner on 12/27/2023 in #help
DateTime.UtcNow returns 0001-01-01T00:00:00
if that's what @baristaner is asking, then indeed EF isn't aware of the changes done by the stored procedure.
51 replies
CC#
Created by baristaner on 12/27/2023 in #help
DateTime.UtcNow returns 0001-01-01T00:00:00
but the savechangesasync will handle the createdAt and modifiedAt
51 replies
CC#
Created by baristaner on 12/27/2023 in #help
DateTime.UtcNow returns 0001-01-01T00:00:00
you can either do the code in C#, or you can let the stored procedure do it
51 replies
CC#
Created by baristaner on 12/27/2023 in #help
DateTime.UtcNow returns 0001-01-01T00:00:00
something like this
51 replies
CC#
Created by baristaner on 12/27/2023 in #help
DateTime.UtcNow returns 0001-01-01T00:00:00
ALTER PROCEDURE [dbo].[GenerateCodes] @NumOfCodes INT = 50, @CharacterSet NVARCHAR(50) = '13456789ACDEFHKLMNPQRTVWXYZ', @ExpirationMonths INT = 3, @ExpirationDate DATE = NULL /* TIME FORMAT ; YYYY-MM-DD */ AS BEGIN SET NOCOUNT ON; DECLARE @Counter INT = 1; BEGIN TRY BEGIN TRANSACTION; WHILE @Counter <= @NumOfCodes BEGIN DECLARE @RandomString VARCHAR(10); SET @ExpirationDate = DATEADD(MONTH, 3, GETDATE()); SET @RandomString = ''; DECLARE @InnerCounter INT = 1; WHILE @InnerCounter <= 10 BEGIN SET @RandomString = @RandomString + SUBSTRING(@CharacterSet, (ABS(CHECKSUM(NEWID())) % LEN(@CharacterSet) + 1), 1); SET @InnerCounter = @InnerCounter + 1; END; SET @UtcNow = GETUTCDATE(); INSERT INTO dbo.Codes (CODE, ExpirationDate,CreatedAt,ModifiedAt,IsActive) VALUES (@RandomString, @ExpirationDate,@UtcNow,@UtcNow,1); SET @Counter = @Counter + 1; END; COMMIT TRANSACTION; END TRY BEGIN CATCH ROLLBACK TRANSACTION; PRINT 'An error occurred. Transaction rolled back.'; PRINT ERROR_MESSAGE(); END CATCH; END;
51 replies
CC#
Created by baristaner on 12/27/2023 in #help
DateTime.UtcNow returns 0001-01-01T00:00:00
I do see createdAt, but not modifiedAt
51 replies
CC#
Created by baristaner on 12/27/2023 in #help
DateTime.UtcNow returns 0001-01-01T00:00:00
you dont insert anything into the ModifiedAt column?
51 replies
CC#
Created by baristaner on 12/27/2023 in #help
DateTime.UtcNow returns 0001-01-01T00:00:00
INSERT INTO dbo.Codes (CODE, ExpirationDate,createdAt,IsActive) VALUES (@RandomString, @ExpirationDate,GETDATE(),1);
51 replies
CC#
Created by baristaner on 12/27/2023 in #help
DateTime.UtcNow returns 0001-01-01T00:00:00
ok lemme check
51 replies
CC#
Created by baristaner on 12/27/2023 in #help
DateTime.UtcNow returns 0001-01-01T00:00:00
if you could copy your sql statement here
51 replies
CC#
Created by baristaner on 12/27/2023 in #help
DateTime.UtcNow returns 0001-01-01T00:00:00
well then i need to see your stored procedure sql statement
51 replies
CC#
Created by baristaner on 12/27/2023 in #help
DateTime.UtcNow returns 0001-01-01T00:00:00
and in the database?
51 replies
CC#
Created by baristaner on 12/27/2023 in #help
DateTime.UtcNow returns 0001-01-01T00:00:00
okay, so it does assign a value to it
51 replies
CC#
Created by baristaner on 12/27/2023 in #help
DateTime.UtcNow returns 0001-01-01T00:00:00
yes plz
51 replies
CC#
Created by baristaner on 12/27/2023 in #help
DateTime.UtcNow returns 0001-01-01T00:00:00
have you confirmed that the state is either added or modified?
51 replies
CC#
Created by baristaner on 12/27/2023 in #help
DateTime.UtcNow returns 0001-01-01T00:00:00
have you debugged your code and checked the code step-by-step inside the savechangesasync?
51 replies
CC#
Created by baristaner on 12/27/2023 in #help
DateTime.UtcNow returns 0001-01-01T00:00:00
Your question is about the UpdateCode function, updating values, and not seeing the expected value back in the database
51 replies
CC#
Created by baristaner on 12/27/2023 in #help
DateTime.UtcNow returns 0001-01-01T00:00:00
unless you have a piece of SQL code that assigns a value to modifiedAt, but let's keep that aside
51 replies
CC#
Created by baristaner on 12/27/2023 in #help
DateTime.UtcNow returns 0001-01-01T00:00:00
yeah it's a stored procedure, why should that even assign a value to modifiedAt from the code?
51 replies
CC#
Created by baristaner on 12/27/2023 in #help
DateTime.UtcNow returns 0001-01-01T00:00:00
Okay so, have you verified whether the state is either Added / Modified?
51 replies