Tôi đang sử dụng EF 6 và sử dụng chiến lược TPT để mô hình hóa vấn đề của mình. Rule
là lớp trừu tượng. OvertimeRule
là một lớp bê tông, kế thừa từ Rule
.EF và TPT: tên cột được chỉ định nhiều lần trong mệnh đề SET
Rule
trông như thế này:
public abstract class Rule
{
public int Id { get; set; }
public PeriodType PeriodType { get; set; }
public int SortOrder { get; set; }
public int StatuteId { get; set; }
public bool IsActive { get; set; }
}
OvertimeRule
trông như thế này:
public partial class OvertimeRule : Rule
{
public decimal? ThresholdCoefficient { get; set; }
public decimal? LimitCoefficient { get; set; }
}
Khi tôi tạo ra một mới OvertimeRule
và cố gắng tiết kiệm nó, EF đầu tiên tạo ra truy vấn này:
INSERT [dbo].[Rules]([PeriodType], [SortOrder], [StatuteId], [IsActive], [StatuteID])
VALUES (@0, @1, @2, @3, @4, @5, @6, NULL)
Như bạn có thể thấy, EF thêm StatuteID
cột để chèn, mà không tồn tại bất cứ nơi nào trong các giải pháp và làm cho điều này một truy vấn SQL không hợp lệ.
SQL sau đó đúng là ném: The column name 'StatuteId' is specified more than once in the SET clause. A column cannot be assigned more than one value in the same SET clause. Modify the SET clause to make sure that a column is updated only once. If the SET clause updates columns of a view, then the column name 'StatuteId' may appear twice in the view definition.
Việc lập bản đồ trông như thế này:
modelBuilder.Entity<Rule>().ToTable("Rules", TimmiSchemaName);
modelBuilder.Entity<Rule>().HasRequired(s => s.Statute).WithMany(s => s.Rules).HasForeignKey(r => r.StatuteId);
modelBuilder.Entity<OvertimeRule>().ToTable("OverTimeRules", TimmiSchemaName);
bất cứ ai có thể cho tôi biết những gì có thể kích hoạt hành vi này?
Hiện nét OvertimeRule của bạn xin vui lòng – tede24
thực hiện. Không có gì thú vị để xem thực sự ở đây .. –