-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EF Core Select error with Guid.Empty #27039
Comments
@markoweb2 The query posted above generates the following SQL with 6.0.1 on SQL Server:
Did you maybe simplify from your real query? Can you attach a small, runnable project or post a small, runnable code listing that reproduces what you are seeing so that we can investigate? |
@ajcvickers - This is the most barebone simplified SQL query that I could write, that would show the error. Ofcourse this is not a real query that I would use. The setup where this bug occurs, is an SQL Server 2017 running on VM (WinServer 2019), database first approach. Is there a public facing Azure SQL database instance, that I could write a small sample app against? If I can reproduce the error, I could send the runnable app project. The only other option I can think of, is creating a minimal database in SQL, create a small app against the database that would show the error. Or a heavy duty approach, I could create a virtual machine, with Win 11 + SQL Express + Visual Studio, that you could launch and then verify the issue. Would have to host this 20-40GB file somewhere to download though (I might have some options)... |
@markoweb2 I just mean something like below. When I run this, it generates the output I posted. If you run it in your environment, do you get something different? public static class Your
{
public static string ConnectionString = @"Data Source=(LocalDb)\MSSQLLocalDB;Database=SixOh";
}
public class Blog
{
public int Id { get; set; }
}
public class SomeDbContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseSqlServer(Your.ConnectionString)
.LogTo(Console.WriteLine, LogLevel.Information)
.EnableSensitiveDataLogging();
public DbSet<Blog> Blogs { get; set; }
}
public class Program
{
public static void Main()
{
using (var context = new SomeDbContext())
{
context.Database.EnsureDeleted();
context.Database.EnsureCreated();
var q = (from s in context.Blogs select new { Id = Guid.Empty }).ToList();
}
}
} |
@ajcvickers - yes, I get an error.
|
@markoweb2 Thanks. @smitpatel Issue happens when iterating over results. SqlClient is returning the value as a string, but metedata is Guid, and hence GetGuid fails.
|
This comment has been minimized.
This comment has been minimized.
@markoweb2 desides the quotes issues, there is a issue tracked by #24075 |
This comment has been minimized.
This comment has been minimized.
Clearing milestone to treat this as a duplicate of #24075; we have a general problem with constant projections and should probably treat it as a single higher-level problem. |
This comment has been minimized.
This comment has been minimized.
Note from triage: tracking as part of #24075. |
This simplest of queries will throw an error:
The error thrown is:
The reason for the error is because the following SQL syntax is generated:
SELECT ''00000000-0000-0000-0000-000000000000'' AS [Id] FROM [WhateverTable] AS [s]
Notice the double single quotes.
Please fix.
EF Core version: 6.0.1
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 6.0
Operating system: Windows 11
IDE: Visual Studio 2022
The text was updated successfully, but these errors were encountered: