Conversions to text: a `char` space is lost, `Convert.ToString(bool)` gives `true`, and `string.Join` with a null separator returns NULL
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 新手友好度
- 80/100
研究方向
Start from NpgsqlStringMethodTranslator.cs (lines 217-225, 274-279) and NpgsqlObjectToStringTranslator.cs (102-107) to pad char values with rpad(x,1); in NpgsqlConvertTranslator.cs (36) use a CASE for bool like bool.ToString. Mimic #4001's rpad fix. Run the issue's repro and confirm the generated SQL matches .NET output (space kept, Convert.ToString(bool) gives True, null separator coalesced).
由索引模型根據 Issue 內容生成。
描述
| Environment | |
|---|---|
| PostgreSQL | 18.6 (postgres:18), session TimeZone Etc/UTC |
| .NET 10 | runtime 10.0.11, Npgsql.EntityFrameworkCore.PostgreSQL 10.0.3, EF Core 10.0.4 |
| .NET 11 | runtime 11.0.0-rc.2, Npgsql.EntityFrameworkCore.PostgreSQL 11.0.0-rc.2, EF Core 11.0.0-rc.2 |
| Also | Npgsql 10.0.3 on both lines, macOS arm64 |
The first repro prints the same output on both lines; the IndexOf one differs by line, as shown. main at 150011d has the same code.
| LINQ | Row | .NET | PostgreSQL | SQL |
|---|---|---|---|---|
string.Join(sep, r.Tags), char sep = ' ' |
{a,b} |
a b |
ab |
array_to_string(r."Tags", @sep, '') |
r.Text.PadRight(4, sep), char sep = ' ' |
abc |
abc␠ |
abc |
rpad(r."Text", 4, @sep) |
r.Space.ToString() |
char column ' ' |
" " |
"" |
r."Space"::text |
r.Text.IndexOf(r.Space), 10.x only |
a b, ' ' |
1 | 0 | strpos(r."Text", r."Space") - 1 |
Convert.ToString(r.Flag) |
true |
True |
true |
r."Flag"::text |
string.Join(r.Separator, r.Tags) |
separator NULL | ab |
NULL | array_to_string(r."Tags", r."Separator", '') |
Repro
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
await using var context = new TestContext();
await context.Database.EnsureDeletedAsync();
await context.Database.EnsureCreatedAsync();
context.Rows.Add(new Row { Tags = ["a", "b"], Space = ' ', Flag = true, Separator = null, Text = "abc" });
await context.SaveChangesAsync();
var row = await context.Rows.AsNoTracking().SingleAsync();
var sep = ' ';
// 1. A space in character(1) is lost when it becomes text
Console.WriteLine($"string.Join(' ' parameter, Tags): .NET {string.Join(sep, row.Tags)}|, database {await context.Rows.Select(r => string.Join(sep, r.Tags)).SingleAsync()}|");
Console.WriteLine($"Text.PadRight(4, ' ' parameter): .NET {row.Text.PadRight(4, sep)}|, database {await context.Rows.Select(r => r.Text.PadRight(4, sep)).SingleAsync()}|");
Console.WriteLine($"Space.ToString(): .NET {row.Space.ToString()}|, database {await context.Rows.Select(r => r.Space.ToString()).SingleAsync()}|");
// 2. bool to text
Console.WriteLine($"Convert.ToString(Flag): .NET {Convert.ToString(row.Flag)}, database {await context.Rows.Select(r => Convert.ToString(r.Flag)).SingleAsync()}");
// 3. string.Join treats a null separator as ""
Console.WriteLine($"string.Join(null separator, Tags): .NET {string.Join(row.Separator, row.Tags)}, database {await context.Rows.Select(r => string.Join(r.Separator, r.Tags)).SingleAsync() ?? "NULL"}");
public class TestContext : DbContext
{
public DbSet<Row> Rows => Set<Row>();
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseNpgsql(Environment.GetEnvironmentVariable("Test__Npgsql__DefaultConnection"), o => o.UseNodaTime())
.LogTo(Console.WriteLine, LogLevel.Information)
.EnableSensitiveDataLogging();
}
public class Row
{
public int Id { get; set; }
public string[] Tags { get; set; } = [];
public char Space { get; set; }
public bool Flag { get; set; }
public string? Separator { get; set; }
public string Text { get; set; } = "";
}
Output (the | marks the end of each value), the same on both lines:
string.Join(' ' parameter, Tags): .NET a b|, database ab|
Text.PadRight(4, ' ' parameter): .NET abc |, database abc|
Space.ToString(): .NET |, database |
Convert.ToString(Flag): .NET True, database true
string.Join(null separator, Tags): .NET ab, database NULL
Repro (`IndexOf` with a char column, 10.x)
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
await using var context = new TestContext();
await context.Database.EnsureDeletedAsync();
await context.Database.EnsureCreatedAsync();
context.Rows.Add(new Row { Text = "a b", Space = ' ' });
await context.SaveChangesAsync();
var row = await context.Rows.AsNoTracking().SingleAsync();
Console.WriteLine($"Text.IndexOf(Space): .NET {row.Text.IndexOf(row.Space)}, database {await context.Rows.Select(r => r.Text.IndexOf(r.Space)).SingleAsync()}");
public class TestContext : DbContext
{
public DbSet<Row> Rows => Set<Row>();
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseNpgsql(Environment.GetEnvironmentVariable("Test__Npgsql__DefaultConnection"), o => o.UseNodaTime())
.LogTo(Console.WriteLine, LogLevel.Information)
.EnableSensitiveDataLogging();
}
public class Row
{
public int Id { get; set; }
public string Text { get; set; } = "";
public char Space { get; set; }
}
Output:
.NET 10, 10.0.3: Text.IndexOf(Space): .NET 1, database 0
.NET 11, 11.0.0-rc.2: Text.IndexOf(Space): .NET 1, database 1
charspaces.charcolumns and parameters arecharacter(1), and castingcharacter(n)totextstrips trailing spaces, so' 'becomes''. #4001 handled this forIndexOfonmainby padding withrpad(x, 1). Three places still lose it:string.Join(NpgsqlStringMethodTranslator.cs#L274-L279),PadLeft/PadRight(NpgsqlStringMethodTranslator.cs#L217-L225) andToString()(NpgsqlObjectToStringTranslator.cs#L102-L107). #4001 came with the new char-argument translations and isn't onhotfix/10.0.4, soIndexOf(char column)stays wrong on 10.x.Convert.ToString(bool)is::text(NpgsqlConvertTranslator.cs#L36).bool.ToString()already uses a CASE that givesTrue/False.string.Jointreats a null separator as empty.array_to_string(..., NULL, '')is NULL, soCOALESCE(separator, '')would match.
- 主要語言
- C#
- 星號
- 1.8k
- 分支
- 268
- 平均合併
- 2 小時 34 分鐘
- 30 天內合併 PR
- 137
環境準備
這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
npgsql/efcore.pg 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 82/100
維護者通常 1 天內回覆
-
NTS: the M ordinate is dropped from geometry SQL literals and from geometries stored in JSON可能已有人在做 @Ahmed7991 於 6 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 85/100
npgsql/efcore.pg#4093 · 1 則留言 ·
維護者通常 1 天內回覆
-
`TimeSpan`/`Duration` component members: negative values are floored, and intervals computed in SQL are read field by field可能已有人在做 @jeremy-morren 於 12 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 70/100
維護者通常 1 天內回覆
-
.NET 11 GA未關閉
難度 2/5 1-3 小時 新手友好度 55/100
npgsql/efcore.pg#4123 · 2 則留言 · 44 個 reaction ·
維護者通常 1 天內回覆
-
Numeric storage parameters are formatted with the current culture, so migrations emit 0,01 instead of 0.01可能已有人在做 @Sorbitol 於 13 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 30/100
維護者通常 1 天內回覆
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 64/100
criticalmanufacturing/cli#909 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 70/100
RadicalCSG/com.chisel#312 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 75/100
eyalgolan/statecraft-israel#3093 · 1 則留言 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 63/100
DeveloperAcademy-POSTECH/2026-C6-M10-MUSA#677 ·
維護者通常 1 天內回覆
-
REQ-13 : une demande En cours perd son responsable par un simple enregistrement, et reste En cours未關閉a-corriger bug
難度 2/5 1-3 小時 新手友好度 76/100
christian-raj/S-Aloha#301 ·