Skip to content

EFCore 10 RC1 - Issue with the generated parameter names #36918

@shvmgpt116

Description

@shvmgpt116

Bug description

In EFCore 10, parameter names are getting simplified due to
#35200

However this change could lead to generated parameter names which are reserved keyword for some database providers.

For Ex:- below LINQ

DateTime date = new DateTime(2024, 1, 1);
var listOfBlogs = context.Blogs.Where(i => i.DateOfPublish > date).ToList();

would generate below SQL with EFCore 10 RC1-

SELECT [b].[BlogId], [b].[DateOfPublish], [b].[Url]
      FROM [Blogs] AS [b]
      WHERE [b].[DateOfPublish] > @date

date is a reserved keyword for Oracle DB and running the LINQ would result in error.

In EFCore 9, the generated SQL is-

SELECT [b].[BlogId], [b].[DateOfPublish], [b].[Url]
      FROM [Blogs] AS [b]
      WHERE [b].[DateOfPublish] > @__date_0

which doesn't have any issue with the parameter name.

Is there any way for the database providers to keep using the old functionality of generating the parameters name?
Or is there a way that database providers can generate their own parameter names?

Your code

#
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
public class Blog
{
  public int BlogId { get; set; }
  public string Url { get; set; }
  public DateTime DateOfPublish { get; set; }
}

public class BloggingContext : DbContext
{
  public DbSet<Blog> Blogs { get; set; }

  protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
  {
    optionsBuilder.UseSqlServer(@"<Connection String>").LogTo(Console.WriteLine);
  }
}

public class Program
{
  public static void Main()
  {
    using (var context = new BloggingContext())
    {
      context.Database.EnsureDeleted();
      context.Database.EnsureCreated();

      if (!context.Blogs.Any())
      {
        context.Blogs.Add(new Blog { Url = "http://blogs.msdn.com/adonet", DateOfPublish = new DateTime(2025, 1, 1) });
        context.Blogs.Add(new Blog { Url = "http://www.google.com", DateOfPublish = new DateTime(2024, 1, 1) });
        context.Blogs.Add(new Blog { Url = "http://www.github.com", DateOfPublish = new DateTime(2023, 1, 1) });
        context.SaveChanges();
      }

      DateTime date = new DateTime(2024, 1, 1);
      var listOfBlogs = context.Blogs.Where(i => i.DateOfPublish > date).ToList();
    }
  }
}

Stack traces


Verbose output


EF Core version

10.0 RC1

Database provider

Microsoft.EntityFrameworkCore.SqlServer

Target framework

.NET 10.0

Operating system

Windows 11

IDE

No response

Metadata

Metadata

Assignees

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions