EntityFramework/CodeFirst Insert Issue

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for MySQL
Post Reply
nickolsky
Posts: 5
Joined: Tue 23 Dec 2014 15:32

EntityFramework/CodeFirst Insert Issue

Post by nickolsky » Tue 23 Dec 2014 15:48

Hello,

I am using entity framework 6, dotConnect MySql 8.3.313.6.

Sample context:

Code: Select all

 public class TestContext : DbContext
    {
        static TestContext()
        {
            Database.SetInitializer(
                new DropCreateDatabaseAlways<TestContext>());
        }

        public TestContext():base("name=TestContext")
        {
            
        }

        public DbSet<TestEntity> TestEntities { get; set; }
    }

    public abstract class BaseEntity
    {
        [StringLength(50)]
        public string CreatedBy { get; set; }

        public DateTime? CreatedOn { get; set; }

        [StringLength(50)]
        public string ModifyBy { get; set; }

        public DateTime? ModifyOn { get; set; }

    }

    public partial class TestEntity : BaseEntity
    {
        public TestEntity()
        {
        }

        [Key]
        [ScaffoldColumn(false)]
        public int TestEntityID { get; set; }


        [StringLength(255)]
        [Required]
        public string Name { get; set; }
        
        [StringLength(50)]
        public string DelimiterRegex { get; set; }
    }
Test request:

Code: Select all

 using (var ctx = new TestContext())
            {
                ctx.TestEntities.Add(new TestEntity
                {
                    Name = "12345",
                    CreatedOn = DateTime.UtcNow,
                    CreatedBy = "admin",
                    ModifyOn = DateTime.UtcNow,
                    ModifyBy = "admin",
                });

                ctx.SaveChanges();
            }
I am getting following error when trying to run code which saves TestEntity to database:
Unhandled Exception: System.Data.Entity.Infrastructure.DbUpdateException: An err
or occurred while updating the entries. See the inner exception for details. ---
> System.Data.Entity.Core.UpdateException: An error occurred while updating the
entries. See the inner exception for details. ---> Devart.Data.MySql.MySqlExcept
ion: You have an error in your SQL syntax; check the manual that corresponds to
your MySQL server version for the right syntax to use near 'VALUES ('12345', NUL
L, 'admin', '2014-12-23 15:35:56.302391', 'admin', '2014-12-' at line 1
When I am changing column DelimiterRegex to something different, it works without exception.
However, we are porting application from MS SQL to My SQL, and I would prefer not to use different column naming, because this will cause issues during transition period.

When I am doing direct insert to MySQL table, it works without issues:

Code: Select all

insert into TestDB.TestEntities
(Name, DelimiterRegex, CreatedOn, CreatedBy, ModifyOn, ModifyBy )
VALUES ('Test', '123', '2014-12-23 19:29:22', 'admin', '2014-12-23 19:29:22', 'admin');
So it looks like problem with insert sql generated by dotConnect EF provider implementation
Sample project here - https://dl.dropboxusercontent.com/u/712 ... SqlBug.zip

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: EntityFramework/CodeFirst Insert Issue

Post by Shalex » Wed 24 Dec 2014 16:53

Thank you for your report. We have reproduced the issue and are investigating it. Please specify the version of your MySQL server.

nickolsky
Posts: 5
Joined: Tue 23 Dec 2014 15:32

Re: EntityFramework/CodeFirst Insert Issue

Post by nickolsky » Wed 24 Dec 2014 18:02

MySql version information:

Code: Select all

+-------------------------+-------------------------+
| Variable_name           | Value                   |
+-------------------------+-------------------------+
| innodb_version          | 5.5.38                  |
| protocol_version        | 10                      |
| slave_type_conversions  |                         |
| version                 | 5.5.38-0ubuntu0.14.04.1 |
| version_comment         | (Ubuntu)                |
| version_compile_machine | x86_64                  |
| version_compile_os      | debian-linux-gnu        |
+-------------------------+-------------------------+

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: EntityFramework/CodeFirst Insert Issue

Post by Shalex » Fri 09 Jan 2015 17:26

The bug with using 'Delimiter' as a part of column or table name is fixed. We will notify you when the corresponding build of dotConnect for MySQL is available for download.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: EntityFramework/CodeFirst Insert Issue

Post by Shalex » Thu 15 Jan 2015 15:56

New build of dotConnect for MySQL 8.3.333 is available for download!
It can be downloaded from http://www.devart.com/dotconnect/mysql/download.html (trial version) or from Registered Users' Area (for users with active subscription only).
For more information, please refer to http://forums.devart.com/viewtopic.php?f=2&t=31097.

nickolsky
Posts: 5
Joined: Tue 23 Dec 2014 15:32

Re: EntityFramework/CodeFirst Insert Issue

Post by nickolsky » Mon 19 Jan 2015 21:23

Thank you. I installed new build MySQL 8.3.333, and issue with 'Delimiter' column does not occur anymore.

Post Reply