Insert datetime with min mysql value in table with Entity Framework - mysql

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 ;-)

Related

Why laravel timestamp fields are nullables?

this is not a technical question.
I'm using laravel for several projects and today I had a doubt: why Laravel timestamp fields are can be null? Is there a portability reason behind this choice or it is only useful?
What is the principle that they applied on this choice?
This is because of MySQL. If they weren't set nullable in some MySQL versions MySQL would put in there own values and when they are marked as nullable, MySQL won't put there own values and values from framework will be used.

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

phpMyAdmin auto insert and display only date

I've got a table with a date-type field
browser transform: text/plain: dateformat
transform option: 0,'%d-%b-%Y','local'
When I execute my query it stores 01-Jan-1970 (default value) and on page it shows me 0000-00-00
What I want to do is to store in database and in page only the date and dateformat Y-m-d like 27.02.2016.
You've got a couple of things going on that I should address first.
The phpMyAdmin transform feature affects how you insert or view data from within phpMyAdmin only. It doesn't change how the data is stored internally with MySQL and it doesn't change how other applications interact with MySQL. So when you talk about displaying in your blog or storing in MySQL, those aren't affected by the transformations you've configured.
Next, you don't appear to be setting the post date, which means you're probably getting '0000-00-00 00:00:00' stored in the column. The exception would be if you allow NULL or set a default value. You can also get zeroes if you insert invalid dates.
The appropriate thing to is use the MySQL type and format the display on output -- either in SQL or in your application; I usually do it in my application. How to do that will depend on which programming language your application uses.
When inserting, you can use NOW() to insert the current time without having to compute it yourself.

Facing problem accessing MySql Timestamp column in Entity Framework

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.

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'