Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.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
Entity framework 如何确定CodeFirst中属性加载的顺序?_Entity Framework_Ef Code First_Code First - Fatal编程技术网

Entity framework 如何确定CodeFirst中属性加载的顺序?

Entity framework 如何确定CodeFirst中属性加载的顺序?,entity-framework,ef-code-first,code-first,Entity Framework,Ef Code First,Code First,我在想,有没有办法确定CodeFirst中属性加载的顺序,例如,我有一个类,如下所示: public Class { public string Propert1{get;set;} public string Propert2{get;set;} public List<string> PropertList{get;set;} } 公共类 { 公共字符串属性1{get;set;} 公共字符串属性2{get;set;} 公共列表属性列表{get;set;} } 我需要在p

我在想,有没有办法确定CodeFirst中属性加载的顺序,例如,我有一个类,如下所示:

public Class
{
 public string Propert1{get;set;}
 public string Propert2{get;set;}
 public List<string> PropertList{get;set;}
}
公共类
{
公共字符串属性1{get;set;}
公共字符串属性2{get;set;}
公共列表属性列表{get;set;}
}

我需要在property1之前创建EF来加载propertyList!(因为我操作Property1_上的propertyList值已更改)。

然后您可以将PropertyList声明为只读

public Class
{
 public string Propert1{get;set;}
 public string Propert2{get;set;}
 public List<String> PropertList{
       get{ 
          return genaratePropertyListFromProperty1();
       }
 }
}
公共类
{
公共字符串属性1{get;set;}
公共字符串属性2{get;set;}
公共列表属性列表{
获取{
返回generatePropertyList fromProperty1();
}
}
}

这里,只有在访问prpertyList时才会填充它。

属性应该是:一个属性。也就是说,你得到或设置了它,没有其他,没有副作用。我知道,即使有些.Net类违反了这一规则,但这仍然是一个非常健康的原则。另一个原则是,设置对象属性的顺序不应该很重要。这是因为设置任何单个属性都会使对象保持有效状态

<>请考虑你的<代码>类< /代码>对象,EF实现它的方式是有效的。然后您可以开始修改它。如果要以同时更改多个属性的方式修改对象,应通过调用具有描述性名称的方法来完成,而不是通过设置一个属性并静默更改其他属性


如果希望列表基于
PropertList
显示不同的内容,请创建一个只读(未映射)属性或
GetXyz()
方法,在其中生成更改的内容(无需修改
PropertList
!)然后返回。

那么,如果直接从数据库加载,为什么需要操作属性1上的
propertylist值?