Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

IsWriteable not working on Key columns

Đang mở
#141 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
csharp, sql
Lĩnh vực
backend, database

Hướng nghiên cứu

Bắt đầu với src/Dapper.Contrib/SqlMapperExtensions.cs tại dòng được liên kết, khoảng dòng 438, và tái hiện trường hợp bảng chỉ có một cột bằng mô hình C# được hiển thị. Theo dõi cách các trường khóa và các trường IsWriteable được chọn cho các thao tác cập nhật, sau đó xác định hành vi mong đợi đối với mệnh đề SET rỗng và việc ghi vào các cột khóa. Hoàn tất khi hành vi cho trường hợp được báo cáo này đã được xác định và bao quát.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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...):

  1. Key column detection sucks, but thats because Dapper isn't checking EF attributes and can be fixed with ExplicitKey attribute.
  2. 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.
  3. 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?

Ngôn ngữ chính
C#
Star
293
Fork
108
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của DapperLib/Dapper.Contrib

Tất cả issue của DapperLib/Dapper.Contrib

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.