Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# EF添加迁移未检测泛型_C#_Entity Framework_Entity Framework Migrations - Fatal编程技术网

C# EF添加迁移未检测泛型

C# EF添加迁移未检测泛型,c#,entity-framework,entity-framework-migrations,C#,Entity Framework,Entity Framework Migrations,我有以下课程 public class PricingRuleNumberRange { public decimal? FromValue { get; private set; } public decimal? ToValue { get; private set; } protected PricingRuleNumberRange() {} public PricingRuleNumberRange(decimal? fromValue, decim

我有以下课程

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
转换为泛型类是可以接受的,但是
addmigration
现在会删除
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;
    }
}
public类PricingRuleNumberRange其中T:struct,IComparable
{
公共T?FromValue{get;private set;}
公共T?ToValue{get;private set;}
受保护的PricingRuleNumberRange(){}
公共PricingRuleNumberRange(T?fromValue,T?toValue)
{
FromValue=FromValue;
ToValue=ToValue;
}
...
}
公共课收费
{
公共PricingRuleNumberRange LVR{get;private set;}
public PricingRuleNumberRange NewCol{get;private set;}
受保护的PricingRule(){}
公共定价(…)
{
...
}
public void UpdateDetails(PricingRuleNumberRange lvr)
{
LVR=LVR;
}
}

因为我在属性声明中指定了
int
/
decimal
,所以我认为它仍然会选择它,但显然不会。我怀疑我可能需要在
DbContext.OnModelCreating()
方法中执行一些操作,或者可能需要在某些属性中添加一些属性以使其正常工作?

原因很清楚。EF确实知道泛型类型
类PricingRuleNumberRange
。因此,我们需要显式地告诉datatypeI,我在PricingRule类中是显式的。当然,反思可以解决这个问题。否则,如何显式地告诉它数据类型?