IsWriteable not working on Key columns
还没有人认领这个 Issue。
评估
调研方向
从 src/Dapper.Contrib/SqlMapperExtensions.cs 中链接行附近的第 438 行开始,使用所示的 C# 模型复现单列表情况。跟踪更新时如何选择键字段和 IsWriteable 字段,然后确定空 SET 子句和写入键列时的预期行为。当已定义并覆盖此报告案例的行为时,即视为完成。
由索引模型根据 Issue 内容生成。
描述
So here I sit and switch from EF to Dapper because CodeFirst with several thousands of AddOrUpdate in Seed was getting a bit irritating when debugging thanks to our beloved Change Tracking... usual story of people switching to Dapper...
... and then I encountered this:
public class WhoInTarnationThoughtThatDozensOfTablesWithOneColumnIsGoodIdea
{
[Key]
[Dapper.Contrib.Extensions.ExplicitKey] //dapper fails to detect his as Key automatically :(
[DatabaseGenerated(DatabaseGeneratedOption.None)]
[StringLength(250)]
public string SomethingNotNamedIdToMakeMyDayWorse { get; set; }
}
So first issue was "Entity must have at least one [Key] or [ExplicitKey] property ", but there are already tickets for it and can be solved with that silly ExplicitKey attribute. No biggie. Build, start, make a tea while this overweight abomination of a project starts up and munches through hundred migrations... oh different exception.
System.Data.SqlClient.SqlException (0x80131904): Incorrect syntax near the keyword 'where'...
Here's the culprit:
https://github.com/DapperLib/Dapper.Contrib/blob/cf24f6bdc577b1e071c3764ddfb2cf3382531405/src/Dapper.Contrib/SqlMapperExtensions.cs#L438
(You won't get exception if you have non-key fields in table. Single-column table is a must.)
So there are 3 problems (aside of database design I got stuck with...):
- Key column detection sucks, but thats because Dapper isn't checking EF attributes and can be fixed with ExplicitKey attribute.
- Invalid SQL when there is no "non-id properties" as SET clause ends up empty. Would be nice to have explicit exception here instead of raw error.
- Due to offending line
[IsWriteable(true)]is not working on Key columns like[DatabaseGenerated(DatabaseGeneratedOption.None)]does in EF, because all Key columns are excluded from list of updateable fields.
So I'd like to ask, before wasting half an hour to fix it, IsWriteable vs ExplicitKey a feature or a bug?
- 主要语言
- C#
- 星标
- 293
- 派生
- 108
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
DapperLib/Dapper.Contrib 的其他 Issue
-
难度 1/5 1 小时以内 新手友好度 75/100
DapperLib/Dapper.Contrib#22 · 2 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 42/100
DapperLib/Dapper.Contrib#174 ·
-
难度 2/5 1-3 小时 新手友好度 45/100
DapperLib/Dapper.Contrib#173 ·
-
难度 1/5 1 小时以内 新手友好度 10/100
DapperLib/Dapper.Contrib#172 · 1 条评论 · 4 个 reaction ·
-
难度 3/5 1-2 天 新手友好度 48/100
DapperLib/Dapper.Contrib#169 ·
查看 DapperLib/Dapper.Contrib 的全部 Issue
相似的 Issue
-
agentic-workflows area/Docs partner/agentic-workflows
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
microsoft/fluentui-blazor#5364 ·
维护者通常 1 天内回复
-
.NET triage
难度 2/5 1-3 小时 新手友好度 74/100
microsoft/agent-framework#8811 ·
维护者通常 1 天内回复
-
.NET Docs
难度 1/5 1 小时以内 新手友好度 82/100
getsentry/sentry-dotnet#5637 · 1 条评论 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
QuantConnect/Lean#9842 ·
维护者通常 1 天内回复