KeyAttribute,PrimaryKey Insert and DevArt for MySql 6.80.325

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for MySQL
Post Reply
insan2006
Posts: 3
Joined: Mon 17 May 2010 12:15

KeyAttribute,PrimaryKey Insert and DevArt for MySql 6.80.325

Post by insan2006 » Mon 19 Mar 2012 08:43

1) Assambly #1 code:

Code: Select all

   
 [Serializable]
    public class BaseEntity : Object
    {

        private Guid _RowGuid = Guid.NewGuid();
        [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        [DescriptionAttribute("Record Ident")]
        public Guid RowGuid // Using Binary(16) as Guid!
        {
            get
            {
                return _RowGuid;
            }
            set
            {
                _RowGuid = value;
                NotifyPropertyChanged(() => RowGuid);
            }
        }
    }
2) Assambly #2 code (reference to #1):

Code: Select all

    [DescriptionAttribute("User"), Serializable]
    public class User : BaseEntity
    {
        [Required, Description("UserName")]
        public string UserName
        {
            get
            {
                return _UserName;
            }
            set
            {
                if (_UserName != value)
                {
                    _UserName = value;
                    NotifyPropertyChanged(() => UserName);
                }
            }
        }
    }
3) Assambly #3 code (reference to #2 and #2)

Code: Select all

    public class EntityContext : DbContext
    {
        public DbSet Users { get; set; }
    }
4) Program (reference to all):

Code: Select all

        static void Main(string[] args)
        {
            EntityContext cnt = new EntityContext();
            User _user = new User();
            _user.RowGuid = Guid.NewGuid();
            _user.UserName = "VPupkin";
            cnt.Users.Add(_user);
            cnt.SaveChanges(); // Exception - RowGuid has no default value!
        }
dbMonitor Trace:

Code: Select all

INSERT INTO Users(UserName)
VALUES (:p0)
;
SELECT RowGuid
  FROM Users
 WHERE RowGuid = last_insert_id() AND ROW_COUNT() = 1;
WTF??!?!

Shalex
Devart Team
Posts: 8083
Joined: Thu 14 Aug 2008 12:44

Post by Shalex » Fri 23 Mar 2012 13:57

Please change

Code: Select all

        [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        [DescriptionAttribute("Record Ident")]
        public Guid RowGuid // Using Binary(16) as Guid!
to

Code: Select all

        [Key]
        [DescriptionAttribute("Record Ident")]
        public Guid RowGuid // Using Binary(16) as Guid!

Post Reply