Facing problem accessing MySql Timestamp column in Entity Framework - mysql

I am using MySql .net connector 6.3.6 and Visual Studio 2008 sp1.
One of the table in the database has a timestamp column.
When I generate Entity mappings (.edmx file), the timestamp column is getting mapped to DateTimeOffset data type.
And when I hit a Linq query on this table, I always get Null value for this column (this column is nullable) even though there are valid non-null values in the table for this column.
If I try to update the mapping to a datetime datatype, visual studio throws error.
I tried to google for possible solutions, and many places it was mentioned that MySql timestamp column should map to .net datetime datatype by default.
I am not sure what the problem is?
Thanks.

I recommend you to try dotConnect for MySQL. It generates DateTime properties for the corresponding Timestamp columns.
You can download a Trial version here, the only limitation of this version is 30-day trial period.
Update. You can try editing the .edmx file using an XML editor. Set the type of the CSDL property to DateTime, and if this causes any validation issues you can try setting the type of the SSDL property to "datetime" as well.

Related

date() and now() functions no longer working in query criteria

I have looked into the references and do not see any libraries with "MISSING" at the end (see image below).
I unchecked and checked the references above that are in use, and that didn't change anything. I then tried to compile the database, and that didn't resolve the issue. I also tried creating a new database and importing all tables, queries, etc. but ran into an error that states "one or more of the newly created objects contain a data type that isn't compatible with earlier versions of access." Is it possible that this is due to updating to datetime2 from datetime? I believe I accepted that change when creating date fields in the Microsoft SQL server management studio.
update: now it appears any criteria associated with using dates is not working. I can't even run a query with the following criteria on a date field:
Between [start_date] And [end_date]

Coldfusion and mySQL 5.6.41 returning datetime errors due to extracted format 2021-02-07T15:32:54

I am getting errors in Mac OS Coldfusion 2016 reading a mySQL 5.6.41 database with field type of datetime. A simple cfquery select * with cfdump produces java class error "java.time.LocalDateTime" on the datetime fields while producing expected data output in all other fields.
Attempting to output the field value as text, it returns the date/time with a T separator '2021-02-07T15:32:54' (which could be parsed).
But no ColdFusion date/time functions work due to this format.
The data was exported from mySQL 5.6.19 via SQL export using Sequel Pro and imported into the new 5.6.41 instance. All code runs fine on the previous server. I have attempted using the installed mySQL 5 datasource in ColdFusion and a JDBC driver. Both connect fine, but produce same DATETIME format.
Changing the field type to DATE or TIMESTAMP allows the CFDUMP to display without error in the DATETIME fields (obviously minus TIME if DATE).
There is a large amount of labor/overhead involved to not be able to keep DATETIME working as built (plus I believe its the correct field type). I have run out of google options and hoping someone can explain the difference and reason and solution the Coldfusion 2016 will not query data in the same manner as similar code/server.
The only way I solved this was to remove mysql-connector-java-8.0.28.jar and replace it with an older version - mysql-connector-java-5.1.38-bin.jar in my case. So, the problem comes from the mySQL connector.

Eloquent Mysql time type precision

I use Laravel 5.6.x framework, i have a connection on a Mysql database of which one of the tables contains a Time(6) field type.
sample value : '00:01:02.154120'
I want my model to receive the value with same precision but i always get a truncated value corresponding to 'H:i:s' format even i cast my column to datetime or string.
I created my table from migration and i saw Blueprint support well precision option for time type since version 5.5. So i guess there is a way to retrieve the whole value ?
How can i achieve this ?
This is a known problem: https://github.com/laravel/framework/issues/24214
It's caused by a bug in PHP that will be fixed in 7.3: https://github.com/php/php-src/pull/3257

Insert datetime with min mysql value in table with Entity Framework

i have a question about the default min value of a date in mysql and entity framework.
I have a a web application that uses entity framework 4.1 and the mysql connector 6.3.6 and in my mysql table i have columns that the need to initialize in the min datettime value of mysql that is '0000-00-00', but from the .NET side, i cant insert that value because the min value of .NET is '0001-01-01' and that gives me many problems. I cant change that the mysql column allow the '0001-01-01' because the mysql table is used in another projects that use that date as a reference, so if i change this for my project, then all the projects will need to update their code and thats is a thing that i dont want to.
So, do i have a solution for this? How can i insert a min mysql value ('0000-00-00') from .NET using entity framework?
Thanks!
You can set default value in MYSQL with your desired format, and pass null value with EF.
Hope isn't mandatory fields ;-)

No datetime values populated from MySQL using SubSonic 3 Linq

I have a MySQL table with a couple of Datetime columns. The columns are set to allow null and some have default value '0000-00-00 00:00:00'. This is a conversion project from ASP to ASP.NET so the table is full of data, and where some rows still have the default value, so I had to set "Allow Zero Datetime=True" in the connectionstring to avoid the exception "Unable to convert MySQL date/time value to System.DateTime"
Now when I generate the code it all works fine and I get properties of type DateTime? for those columns, but when I query the database and populate an object representing the table all DateTime properties are null. Other properties gets populated their correct values.
Anybody knows why?
I'm using MySQL Connector 6.1.3 and SubSonic.Core compiled from the github today (11/17/2009)
I did some data cleaning. Updated all datetime columns to null where date was '0000-00...' and removed "Allow Zero Datetime=True" from the connectionstring, and then it works. Guess zero dates are not supported by SubSonic, and why should it, I donĀ“t see any use for zero dates over null.
My trick for converting datetime format from different SQL DBMS is to load the column as VARCHAR. Then use string functions such as SUBSTRING and CONCAT to play around and get the desire format. From experience this saves a lot of time. No need to worry about dbms automatic conversion for datetime.
MySQL uses 'YYYY-MM-DD HH:MM:SS'