Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/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
Methods 我可以在实体框架中用作实体的类中放置一个方法吗?_Methods_Ef Code First_Entity - Fatal编程技术网

Methods 我可以在实体框架中用作实体的类中放置一个方法吗?

Methods 我可以在实体框架中用作实体的类中放置一个方法吗?,methods,ef-code-first,entity,Methods,Ef Code First,Entity,我有实体框架使用的POCO类。我使用一个未与数据库映射的字段,因为我希望在访问某个数据行时对其进行计算 我是否可以将数据处理转移到该类中的某个方法,并期望实体框架能够正常工作 public class SomeClass { public int Id { get; set; } public string Variable { get; set; } [NotMapped] public string VariableProcessed {

我有实体框架使用的POCO类。我使用一个未与数据库映射的字段,因为我希望在访问某个数据行时对其进行计算

我是否可以将数据处理转移到该类中的某个方法,并期望实体框架能够正常工作

public class SomeClass
{
    public int Id { get; set; }
    public string Variable { get; set; }

    [NotMapped]
    public string VariableProcessed
    {
        get
        {
             return Variable.DoSomethingBlaBla();
        }
        set {}
    }
}
我想这样重写它:

public class SomeClass
{
    public int Id { get; set; }
    public string Variable { get; set; }

    [NotMapped]
    public string VariableInverted
    {
        get
        {
             return ProcessVariable(Variable);
        }
        set {}
    }

    private int ProcessVariable(string variable) 
    { 
        return variable.DoSomethingBlaBla();
    }
}

是的,你可以。但只要该函数对POCO类中的变量起作用,就不需要向该函数传递参数