Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.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
Asp.net mvc 4 EditorForModel不使用ICollection MVC 4_Asp.net Mvc 4_Entity Framework 4 - Fatal编程技术网

Asp.net mvc 4 EditorForModel不使用ICollection MVC 4

Asp.net mvc 4 EditorForModel不使用ICollection MVC 4,asp.net-mvc-4,entity-framework-4,Asp.net Mvc 4,Entity Framework 4,我们有以下型号: public class Sample { public int SampleId { get; set; } public int ToTestId { get; set; } public int Name { get; set; } public virtual ICollection<SampleCondition> Child_SampleConditions { get; set; } } 它只返回[0].Conditi

我们有以下型号:

public class Sample
{
    public int SampleId { get; set; }
    public int ToTestId { get; set; }
    public int Name { get; set; }
    public virtual ICollection<SampleCondition> Child_SampleConditions { get; set; }
}
它只返回[0].ConditionValue,但不返回子\u SampleConditions[0].ConditionValue

请告知

谢谢。

而不是:

O => sampleConditions[0].ConditionValue
写:

O => O.Child_SampleConditions[0].ConditionValue
编辑:

使用IList创建ViewModel,因为ICollection无法编制索引:

public class SampleVM
{
    public int SampleId { get; set; }
    public int ToTestId { get; set; }
    public int Name { get; set; }
    public virtual IList<SampleCondition> Child_SampleConditions { get; set; }
}

参考链接:

否,不起作用。它给出编译时错误:错误4无法对“System.Collections.Generic.ICollection”类型的表达式应用带[]的索引。您无法通过创建视图模型为ICollection使用IList编制索引。我认为我无法更改模型。它们是由建筑师设计的。将ICollection更改为IList是否会产生任何后果?您必须创建一个特定于视图的视图模型,而不是您的数据模型,如何将我的数据模型分配给视图模型?
O => O.Child_SampleConditions[0].ConditionValue
public class SampleVM
{
    public int SampleId { get; set; }
    public int ToTestId { get; set; }
    public int Name { get; set; }
    public virtual IList<SampleCondition> Child_SampleConditions { get; set; }
}