我有以下课程;
public class PricingRuleNumberRange
{
public decimal? FromValue { get; private set; }
public decimal? ToValue { get; private set; }
protected PricingRuleNumberRange() {}
public PricingRuleNumberRange(decimal? fromValue, decimal? toValue)
{
FromValue = fromValue;
ToValue = toValue;
}
...
}
使用所述类的模型;
public class PricingRule
{
public PricingRuleNumberRange LVR { get; private set; }
protected PricingRule() { }
public PricingRule(...)
{
...
}
public void UpdateDetails(PricingRuleNumberRange lvr)
{
LVR = lvr;
}
}
我可以向PricingRuleNumberRange
添加新的PricingRule
属性并调用Add-Migration
,它会检测并支持更改而不会出现问题。但是,我现在需要添加另一个PricingRuleNumberRange
属性,该属性仅为int
,而不是decimal
。我认为将PricingRuleNumberRange
转换为通用类是可以接受的,但Add-Migration
现在会删除LVR
属性/列。
这是新代码;
public class PricingRuleNumberRange<T> where T : struct, IComparable<T>
{
public T? FromValue { get; private set; }
public T? ToValue { get; private set; }
protected PricingRuleNumberRange() {}
public PricingRuleNumberRange(T? fromValue, T? toValue)
{
FromValue = fromValue;
ToValue = toValue;
}
...
}
public class PricingRule
{
public PricingRuleNumberRange<decimal> LVR { get; private set; }
public PricingRuleNumberRange<int> NewCol { get; private set; }
protected PricingRule() { }
public PricingRule(...)
{
...
}
public void UpdateDetails(PricingRuleNumberRange<decimal> lvr)
{
LVR = lvr;
}
}
由于我在属性声明中指定int
/ decimal
,我认为它仍然可以提取它,但显然不是。我怀疑我可能需要在DbContext.OnModelCreating()
方法中执行某些操作,或者可能会为某些属性添加一些属性以使其起作用?