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.

Exception when updating DateTime? Field

See original GitHub issue

First off, awesome library!

I’m trying to set my UpdatedAt timestamp using the WhenMatched() call. Here is my code:

_context.Earnings.Upsert(new Earnings
{
    EmployeeId = employee.Id,
    ContributionGroupId = employee.CurrentEmploymentRecord.ContributionGroupId,
    JobPosition = employee.CurrentEmploymentRecord.JobPosition,
    PositionStatus = employee.CurrentEmploymentRecord.PositionStatus,
    PaymentReason = employee.CurrentEmploymentRecord.PaymentReason,
    ImportType = ImportType.MonthEnd,
    PostingDate = new DateTime(UploadEarnings.Year, UploadEarnings.Month, 1),
    GrossEarnings = earning.Amount.GetValueOrDefault(),
    CreatedAt = DateTime.Now,
})
.On(c => new { c.EmployeeId, c.ContributionGroupId, c.JobPosition, c.PositionStatus, c.PaymentReason, c.ImportType, c.PostingDate })
.WhenMatched(c => new Earnings
{
    UpdatedAt = DateTime.Now,
    GrossEarnings = earning.Amount.GetValueOrDefault()
})
.Run();

I receive the following exception when trying to set the UpdatedAt value:

The method or operation is not implemented.

If I omit UpdatedAt or try to set CreatedAt in WhenMatched() I do not get the exception. The only difference between the two is that CreatedAt is a DateTime type and UpdatedAt is DateTime?. Also, If I set UpdatedAt in the Upsert() call, I do not get the exception. I’m a newbie, so maybe I’m missing something?

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
barrettgcommented, Nov 6, 2018

Sorry for the delay in my response… You are correct, it is an issue of of the property being nullable. If I declare a local variable of DateTime? updatedAt = DateTime.Now; and then use that value in WhenMatched() it works. I have also tested version 2.0.2 and the issue is fixed when using the code unmodified from above. Thanks!!!

0reactions
artiomchicommented, Nov 3, 2018

Right, I believe I got this working in the latest version, which is being deployed now: v2.0.2

Please let me know if the parch works, and if we can close this issue 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Updating datetime field from a date field throws error in ...
This will supply a varchar value in the format yyyy-MM-ddThh:mm:ss.nnn . For example, with GETDATE() I get the value '2019-11-27T12:32:27.763' ...
Read more >
Cannot update nor insert data to datetime field [closed]
So you typed the varchar value 'Receive' in another column of data type int , and it most likely has nothing to do...
Read more >
Cannot update DateTime field
Hello,. having trouble setting a datetime typed field. downloadDate__c is a custom field. I'm trying to set the value by assigning to it...
Read more >
update datetime field?? - SQL Server Forums
i want to update date field but i am getting error like update emp set convert(varchar(50),date_t,121) = '2006-03-31 19:56:36.933'
Read more >
Error while inserting/Updating DateTime field
Hi,. We are trying to update dateTime field using. https://www.methodintegration.com/MethodAPI/service.asmx/MethodAPIUpdateV2.
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