Page 1 of 1

Contains not compatible with GuidToStringConverter in EF Core

Posted: Tue 04 Dec 2018 14:08
by Zerda
# Background
- dotConnect for Oracle 9.6.646
- EntityFramework Core 2.1.4
- .Net Core 2.1.2

# Issue description
Say I need to mapping System.Guid to CHAR(36), it's done with GuidToStringConverter as shown in following POC.

And it's correctly converted to string type when Find(id) or Where(item => item.Id == id), but still converted to binary when Contains(item.Id).

It looks like a bug to me, would you please check, Thanks.

Code: Select all

class Program
{
  static void Main(string[] args)
  {
    var id = Guid.Parse("06a1472e-62a9-4add-942d-ba5b83f0c2c4");
    using(var dbContext = new MyDbContext()) {
      dbContext.Database.EnsureCreated();
      var found = dbContext.Items.Find(id);
      Console.WriteLine(found?.Id); // got '06a1472e-62a9-4add-942d-ba5b83f0c2c4'
      // Executed DbCommand (79ms) [Parameters=[p__get_Item_0='06a1472e-62a9-4add-942d-ba5b83f0c2c4' (Size = 36)], CommandType='Text', CommandTimeout='0']
      // SELECT "e"."Id"
      // FROM "Items" "e"
      // WHERE ("e"."Id" = :p__get_Item_0) AND ((ROWNUM) <= 1)

      var count = dbContext.Items.Count(item => new[]{id}.Contains(item.Id));
      Console.WriteLine(count); // should be 1, got 0
      // Executed DbCommand (11ms) [Parameters=[p__id_0='06a1472e-62a9-4add-942d-ba5b83f0c2c4' (Nullable = true) (DbType = Binary)], CommandType='Text', CommandTimeout='0']
      // SELECT Count(*)
      // FROM "Items" "item"
      // WHERE "item"."Id" IN (:p__id_0)
    }
  }
}

public class MyDbContext : DbContext {
  public static readonly LoggerFactory MyLoggerFactory = new LoggerFactory(new[] {new ConsoleLoggerProvider((_, __) => true, true)});
  protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
  {
    optionsBuilder
      .EnableSensitiveDataLogging()
      .UseLoggerFactory(MyLoggerFactory)
      .UseOracle("REDACTED");
  }

  protected override void OnModelCreating(ModelBuilder modelBuilder)
  {
    modelBuilder.Entity<Item>().Property(item => item.Id)
      .ForOracleHasColumnType("CHAR(36)")
      .HasConversion(new GuidToStringConverter());
  }

  public DbSet<Item> Items { get; set; }
}

public class Item
{
  public System.Guid Id { get; set; }
}

Re: Contains not compatible with GuidToStringConverter in EF Core

Posted: Wed 05 Dec 2018 20:09
by Shalex
Thank you for your report. We have reproduced the issue and are investigating it. We will notify you about the result.

Re: Contains not compatible with GuidToStringConverter in EF Core

Posted: Thu 10 Jan 2019 18:45
by Shalex
The bugs with using the GuidToStringConverter, EnumToStringConverter, ValueConverter classes in EF Core 2 are fixed: viewtopic.php?f=1&t=38262.

Re: Contains not compatible with GuidToStringConverter in EF Core

Posted: Sat 26 Jan 2019 14:54
by Zerda
Thank you for the new version. The origin scenario is fixed, but I have found some variants need to be fixed too.

# Background
- dotConnect for Oracle 9.6.675
- EntityFramework Core 2.2.0
- .Net Core 2.2.0

When the guid collection are defined as a variable, guid is casted to RAW(16), which expected to be CHAR(36).

Code: Select all

// var ids = new[] { id }; would be same result
var ids = new List<Guid> { id }; 
var count = dbContext.Items.Count(item => ids.Contains(item.Id));

// Executed DbCommand (7ms) [Parameters=[], CommandType='Text', CommandTimeout='0']
// SELECT Count(*)
// FROM "Items" "item"
// WHERE "item"."Id" IN (CAST('2E47A106A962DD4A942DBA5B83F0C2C4' AS RAW(16)))
As always, thank you.

Re: Contains not compatible with GuidToStringConverter in EF Core

Posted: Thu 31 Jan 2019 19:49
by Shalex
Thank you for your report. We will investigate the question and notify you about the result.

Re: Contains not compatible with GuidToStringConverter in EF Core

Posted: Mon 18 Feb 2019 13:38
by Shalex
The bug with using a value converter for the property used in .Contains() in EF Core 2 is fixed: viewtopic.php?f=1&t=38378.