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

SqlMapperExtensions.cs error when Computed Id property defined where ExplictKey set on other property

Đang mở
#118 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ó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
55/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
csharp
Lĩnh vực
databases

Hướng nghiên cứu

Bắt đầu trong SqlMapperExtensions.cs tại GetSingleKey() và kiểm tra cách KeyPropertiesCache và ExplicitKeyPropertiesCache được tra cứu đối với dạng model đã cho. Xác minh rằng thay đổi đã hoàn tất xử lý một Id ngầm định cùng với một ExplicitKey mà không coi cả hai là khóa, bao gồm trường hợp thuộc tính không theo tiêu chuẩn có [ExplicitKey].

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

Mô tả

There is an issue when an id property is defined in a class where another property on the class has an explicit key.
Consider this scenario where we are using a computed property to set a 'standard' Id property where a table uses a non-standard primary key naming.

using Dapper.Contrib.Extensions;

namespace MyNamespace
{
    [Table("ABC_Table")]
    public class MyTable 
    {
        [ExplicitKey]
        public int SomePrimaryKeyId { get; set; }
        [Computed]
        public int Id { get => SomePrimaryKeyId; set => SomePrimaryKeyId = value; }
        public string OtherProp { get; set; }
    }
}

This causes an issue in GetSingleKey() when KeyPropertiesCache does not find a [Key] attr and tries to find an implicit key using the id property name. The KeyPropertiesCache returns Id as a key but the ExplicitKeyPropertiesCache also returns the named key.

In the situation where an implicit key is found, it should also check if any ExplicitKey exists.
Note this does not have a problem when SomePrimaryKeyId is decorated with [Key], only [ExplicitKey] causes an issue.

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.