Object null exception on Guid property

Object null exception on Guid property

Postby ermac0 » Tue 02 Oct 2012 14:19

I'm testing mysql connect for EF (7.2.77) and I'm getting object null exceptions when I try to batch-load entities using property matching of type Guid. It perfectly works on other types like int or string.

Code I use:

Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace DevartMySQLTest
{
    class Test
    {
        public static void Run()
        {
            var test = new Test();
            test.InsertData();
            test.TestID();
            test.TestGuid();
        }

        private void InsertData()
        {
            using (var ctx = new MyDbContext())
            {
                ctx.CreateDB();

                if (ctx.Entity1Set.Count() < 1000)
                {
                    for (var i = 0; i < 1000; i++)
                    {
                        var entity = new Entity1()
                        {
                            Guid = Guid.NewGuid(),
                        };

                        ctx.Entity1Set.Add(entity);
                    }
                    ctx.SaveChanges();
                }
            }
        }

        private void TestID()
        {
            using (var ctx = new MyDbContext())
            {
                var ids = ctx.Entity1Set.OrderBy(x => x.ID).Skip(100).Take(100).Select(x => x.ID).ToList();
                var items = ctx.Entity1Set.Where(x => ids.Contains(x.ID)).ToList();

                if (items.Count != 100)
                {
                    throw new Exception("Failed.");
                }
            }
        }

        private void TestGuid()
        {
            using (var ctx = new MyDbContext())
            {
                var guids = ctx.Entity1Set.OrderBy(x => x.ID).Skip(100).Take(100).Select(x => x.Guid).ToList();

                // it errors here
                var items = ctx.Entity1Set.Where(x => guids.Contains(x.Guid)).ToList();

                if (items.Count != 100)
                {
                    throw new Exception("Failed.");
                }
            }
        }
    }

    class MyDbContext : DbContext
    {
        public MyDbContext()
            : base("TestDB")
        {
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
        }

        public void CreateDB()
        {
            this.Database.CreateIfNotExists();
        }

        public IDbSet<Entity1> Entity1Set { get; set; }
    }

    public class Entity1
    {
        [Required]
        [Key, Column(Order = 0)]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int ID { get; set; }

        [Required]
        public Guid Guid { get; set; }

        public string Name { get; set; }
    }
}

    // run tests
    Test.Run();


I use test database with a connection string named TestDB.

Any idea whether that's a bug?
Thanks
ermac0
 
Posts: 2
Joined: Tue 02 Oct 2012 14:09

Re: Object null exception on Guid property

Postby Shalex » Tue 09 Oct 2012 12:35

Thank you for your report. We have reproduced System.NullReferenceException with your code and are investigating the issue. We will post here about the results.
Shalex
Devart Team
 
Posts: 7530
Joined: Thu 14 Aug 2008 12:44

Re: Object null exception on Guid property

Postby Shalex » Wed 17 Oct 2012 09:53

The bug with retrieving entities using Guid constants or the .Contains operation for Guid collection is fixed. We will post here when the corresponding build of dotConnect for MySQL is available for download.
Shalex
Devart Team
 
Posts: 7530
Joined: Thu 14 Aug 2008 12:44

Re: Object null exception on Guid property

Postby ermac0 » Mon 22 Oct 2012 18:03

Cheers!
ermac0
 
Posts: 2
Joined: Tue 02 Oct 2012 14:09

Re: Object null exception on Guid property

Postby Shalex » Wed 24 Oct 2012 16:34

The fix is available in the current (7.2.104) build of dotConnect for MySQL. Please try it and notify us about the results.
Shalex
Devart Team
 
Posts: 7530
Joined: Thu 14 Aug 2008 12:44


Return to dotConnect for MySQL