sql-server - 不支持使用“身份”模式修改列。列:'ID'。表:'CodeFirstDatabaseSchema.BidTo'
问题描述
直到今天早上,这个问题都不存在。但是,现在,当我尝试将身份字段不是主键的表插入到表中时,我得到了上述错误。
配置:
public BidToConfiguration()
{
ToTable("BidTo");
HasKey(bt => new { bt.BidRecipientCode, bt.ProposalNumber });
Property(bt => bt.Awarded)
.IsOptional();
Property(bt => bt.BidRecipientCode)
.IsRequired()
.HasMaxLength(10);
Property(bt => bt.BidValue)
.IsRequired();
Property(bt => bt.ContactEmail)
.IsOptional()
.HasMaxLength(150);
Property(bt => bt.ContactName)
.IsOptional()
.HasMaxLength(150);
Property(bt => bt.ContactPhone)
.IsOptional()
.HasMaxLength(25);
Property(bt => bt.ID)
.IsRequired()
.HasDatabaseGeneratedOption(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity);
Property(bt => bt.LastChanged)
.IsRequired();
Property(bt => bt.LastChangedBy)
.IsRequired()
.HasMaxLength(50);
Property(bt => bt.ProposalNumber)
.IsRequired()
.HasMaxLength(15);
Property(bt => bt.ReqForBidNumber)
.IsOptional()
.HasMaxLength(50);
HasRequired(bt => bt.BidRecipient)
.WithMany(br => br.BidTos)
.HasForeignKey(bt => bt.BidRecipientCode);
}
插入此表:
BidTo newBidTo = new BidTo();
newBidTo.Awarded = bt.Awarded;
newBidTo.BidRecipientCode = bt.BidRecipientCode;
newBidTo.BidValue = bt.BidValue;
newBidTo.ContactEmail = bt.ContactEmail;
newBidTo.ContactName = bt.ContactName;
newBidTo.ContactPhone = bt.ContactPhone;
newBidTo.ID = bt.ID;
newBidTo.LastChanged = DateTime.Now;
newBidTo.LastChangedBy = User.Identity.Name;
newBidTo.ProposalNumber = proposal.ProposalNumber;
newBidTo.ReqForBidNumber = bt.ReqForBidNumber;
_dbpm.BidTos.Add(newBidTo);
当我执行 context.SaveChanges() 时,无论我是否有“newBidTo.ID = bt.ID;”行,我都会收到错误消息 注释掉与否。
添加:一个注意,这个表,但不是其他两个具有相同错误的表有一个 INSERT/UPDATE/DELETE 触发器。
解决方案
推荐阅读
- microsoft-cognitive - 表单识别器标签工具请求表单链接似乎已损坏
- javascript - 源代码在哪里更改以点呈现希伯来文本?PDF JS
- html - 如何响应地均匀分布文本?
- javascript - Video.play() 导致 TypeError
- c# - 从客户端获取承载或 AuthResult?
- r - 无法将 highcharter (R) 中的功能区与法线系列组合
- .net - 无法在 VS2019 的代码中找到正确的调试点
- c# - Automapper:有什么理由更喜欢完全类型化的映射函数?
- r - 创建新变量附加变量(如月份)的值并横向扩展数据?
- sql - 如何从 postgresql 中的工作日编号获取日期名称?