我收到空错误ORA-01407:使用实体框架通过代码更新记录时,无法将(“ MGR”。“ MGR_STRT_CLASSIFICATION”。“ PRODUCT_ID”)更新为NULL,但是更新脚本在数据库中运行正常
我在表的两列上都有唯一的约束,即PRODUCT_ID和MANAGERSTRATEGYID
如果我在数据库中运行此代码,它将运行正常。注意,我尚未将PRODUCT_ID和MANAGERSTRATEGYID与表中的值一起使用,否则将是唯一的约束冲突。
update mgr.MGR_STRT_CLASSIFICATION
set managerstrategyid = 7079,
Legacy_Strategy_ID = 19,
managerstrategy_Type_id = 1
where ID = 760
在我的服务器代码中,我执行以下操作,并得到错误product_id不能为空
var mgrClassificationService = GetService<MGR_STRT_CLASSIFICATION>();
var isExists = mgrClassificationService.Where(x =>
x.MANAGERSTRATEGYID == model.ManagerStrategyId && x.PRODUCT_ID == model.ProductId).FirstOrDefault();
if (isExists == null)
{
var mgrClassficationOverride = new MGR_STRT_CLASSIFICATION();
if (model != null)
{
mgrClassficationOverride.ID = model.ID;
mgrClassficationOverride.PRODUCT_ID = model.ProductId;
mgrClassficationOverride.LEGACY_STRATEGY_ID = model.LegacyStrategyId;
// mgrClassficationOverride.STRATEGY_ID = model.StrategyId;
mgrClassficationOverride.MANAGERSTRATEGY_TYPE_ID = model.ManagerStrategyTypeId;
mgrClassficationOverride.MANAGERSTRATEGYID = model.ManagerStrategyId;
mgrClassificationService.Update(mgrClassficationOverride);
}
response = Request.CreateResponse(HttpStatusCode.OK, mgrClassficationOverride);
}
else
{
var mgrClassficationOverride = new MGR_STRT_CLASSIFICATION();
if (model != null)
{
mgrClassficationOverride.ID = model.ID;
mgrClassficationOverride.LEGACY_STRATEGY_ID = model.LegacyStrategyId;
mgrClassficationOverride.MANAGERSTRATEGY_TYPE_ID = model.ManagerStrategyTypeId;
//mgrClassficationOverride.PRODUCT_ID = model.ProductId;
//mgrClassficationOverride.MANAGERSTRATEGYID = model.ManagerStrategyId;
mgrClassificationService.Update(mgrClassficationOverride);
}
response = Request.CreateResponse(HttpStatusCode.OK, mgrClassficationOverride);
}
return response;
ViewModel
public class ClassificationItemViewModelCreate
{
public int ID { get; set; }
public int ManagerStrategyId { get; set; }
public int? ProductId { get; set; }
public int? StrategyId { get; set; }
public int? LegacyStrategyId { get; set; }
public int? ManagerStrategyTypeId { get; set; }
}
实体
public class MGR_STRT_CLASSIFICATION : Entity, ILegacyStrategy
{
public int MANAGERSTRATEGYID { get; set; }
public int? PRODUCT_ID { get; set; }
public int? STRATEGY_ID { get; set; }
public int? SUB_STRATEGY_ID { get; set; }
public int? SECTOR_FOCUS_ID { get; set; }
public int? REGIONAL_FOCUS_ID { get; set; }
public int? LEGACY_STRATEGY_ID { get; set; }
public int? MANAGERSTRATEGY_TYPE_ID { get; set; }
////public string OVERRIDE_NOTES { get; set; } need to add
[ForeignKey("PRODUCT_ID")]
public V_PRODUCT PRODUCT { get; set; }
[ForeignKey("MANAGERSTRATEGYID")]
public MANAGERSTRATEGY MANAGERSTRATEGY { get; set; }
[ForeignKey("LEGACY_STRATEGY_ID")]
public LEGACY_STRATEGY LEGACYSTRATEGY { get; set; }
public override string ToString() {
return string.Format("MGR_STRT_CLASSIFICATION: ID={0}", this.ID);
}
}