What is the alternate for GETDATE()
in LINQ?
I got some workaround from the following post:
Is there any better approach? In which, there is no need to an ExecuteQuery
or a separate function call?
As far as I can see with linq to sql the post you refer to is the way to go. I don't see how anything could be better. It's a pretty elegant solution.
With Entity Framework there is a possibility to use SqlFunctions.CurrentTimestamp
. Besides that, even when you use DateTime.Now
in linq to entities (not linq to sql) it is translated to GetDate
:
context.Companies.Select (c => DateTime.Now);
translates:
SELECT
GetDate() AS [C1]
FROM [dbo].[Company] AS [Extent1]
It's a different story if you only want to get the database date. In that case I don't see how anything could beat executing a query SELECT GetDate()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With