2014-10-29 40 views
0

我首先使用实体​​框架代码。 我有两个非常类似的虚拟ICollection属性类。 这里是集合类其中之一:如何从虚拟ICollection中返回EnityCollection?

public class Name 
{ 
    public int Id{ get; set;} 

    [MaxLength(64)] 
    [Index(IsUnique = true)] 
    [Required] 
    public string Value { get; set; } 

    public virtual ICollection<NameVariant> Variants { get; set; } 
} 

public class NameVariant 
{ 
    public int Id{ get; set;} 

    [MaxLength(64)] 
    [Index(IsUnique = true)] 
    [Required] 
    public string Value { get; set; } 

    public int ParentId { get; set; } 

    public virtual Name Parent { get; set; } 
} 

我在另外一个案例和HashSet的获得EntityCollection的变体。 它取决于什么?我如何从这两个类获得EnityCollection?

回答

4

该成员声明它将返回一个接口。您需要对该接口进行编码,并假定代码可以返回任何类型,只要该类型实现该接口,而不是依赖于返回的特定具体实现。