GetDate () using Entity Framework

I am trying to use an entity structure and get a date from an SQL server. The old way to do this in LINQ is below, but I need something for the entity framework:

Partial Public Class ActivityActionsDataContext
<[Function](Name:="GetDate", IsComposable:=True)> _
Public Function GetSystemDate() As DateTime
    Dim mi As MethodInfo = TryCast(MethodBase.GetCurrentMethod(), MethodInfo)
    Return DirectCast(Me.ExecuteMethodCall(Me, mi, New Object() {}).ReturnValue, DateTime)
End Function

Final class

+3
source share
3 answers

Have you tried using DateTime.Nowor DateTime.UtcNow? I would like to think that the query translator will be converted to GetSystemDate().

+1
source

Canonical EF function to return UTC date time: CurrentUtcDateTime()

See also: http://msdn.microsoft.com/en-us/library/bb738563.aspx

+2
source

Search for “efquerysamples” on Google and download these good examples, then look at the canonical function CurrentDateTime (), it worked with:

DateTime fecha = ServicioContexto.Contexto.CreateQuery ("CurrentDateTime ()"). Run (MergeOption.NoTracking) .First ();

I would like to learn more about canonical functions. Please explain me. thank you

+1
source

Source: https://habr.com/ru/post/1705368/


All Articles