无法序列化System.Collections.Generic.ICollection类型的成员X,因为它是一个接口

时间:2017-01-28 23:19:35

标签: c# entity-framework

我有一个返回List的ASMX文件。我正在使用EntityFramework和Database First模式。

我使用Visual Studio创建了EDMX。我有User,Stock和UserStockRelation表。 User类如下所示

public User()
{
    this.UserStockRelation = new HashSet<UserStockRelation>();
}

public int Id { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public Nullable<bool> Active { get; set; }
public Nullable<System.DateTime> CreatedDate { get; set; }

public virtual ICollection<UserStockRelation> UserStockRelation { get; set; }

由于ICollection,它返回我在标题中提到的错误。如果我将ICollection转换为List,则会给出以下错误...

Cannot implicitly convert type System.Collections.Generic.HashSet<UserStockRelation> to System.Collections.Generic.List<UserStockRelation>

我该如何解决这个问题?

0 个答案:

没有答案