0

I'm using Entity Framework 4 with MySql.Data.MySqlClient provider.

May I know where is CurrentDateTime() listed in http://msdn.microsoft.com/en-us/library/bb738563(v=vs.100).aspx?

I've tried namespace System.Data.Metadata.Edm and System.Data.Objects but with no luck...

UPDATE: I've just found out that I can use DateTime.Now instead of CurrentDateTime() for the DB time. It will be translated into NOW() in the query.

The problem now is that EntityFunctions.AddDays() doesn't work. It's not translated into the correct ADDDATE() but AddDays(). Does that mean Canonical Functions are not supported by MySql? (MySql connector net 6.5.4)

Lance Roberts
  • 22,383
  • 32
  • 112
  • 130
Leon
  • 1,011
  • 1
  • 11
  • 28
  • it sounds correct . may you put your code here ? – mohsen dorparasti Mar 09 '12 at 18:34
  • Does this answer your question? [How to ask the database server for current datetime using entity framework?](https://stackoverflow.com/questions/2585272/how-to-ask-the-database-server-for-current-datetime-using-entity-framework) – Michael Freidgeim Feb 12 '23 at 05:20

3 Answers3

0

You can use this query to get sysdate from MySql server using entity framework:

DateTime _serverDate=dbContext.CreateQuery<DateTime>("CurrentDateTime() ").AsEnumerable().First();
giampaolo
  • 6,906
  • 5
  • 45
  • 73
0

try these links . I think you can find your answer there

CurrentDateTime() in EF

How to ask database server for current datetime using entity framework?

Community
  • 1
  • 1
mohsen dorparasti
  • 8,107
  • 7
  • 41
  • 61
0

In case of ESQL you will just use "CreateDateTime(...)". In case of Linq-to-Entities you will use: System.Data.Objects.EntityFunctions.CreateDateTime(...)

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
  • I just found out that I can use DateTime.Now for the CurrentDateTime. However, when I tried EntityFunctions.AddDays, it gives me an error: FUNCTION .AddDays does not exist. Does that mean it doesn't work with MySql? (MySql connector net 6.5.4) – Leon Mar 13 '12 at 13:02
  • When I looked at the query. It didn't translate into the correct ADDDATE() but AddDays(). – Leon Mar 13 '12 at 13:17