【发布时间】:2015-08-24 13:36:50
【问题描述】:
我收到一个奇怪的错误。几天前代码运行良好。但现在它的抛出错误。我试图用谷歌搜索找出解决方案,但找不到。 我首先在实体框架中使用代码创建实体。现在,在实体框架中首先使用代码添加新实体并在 MVC 中使用 WCF 服务使用方法时,它开始在 UI 部分 (MVC) 中引发错误,例如
错误:无法将类型“Campus.Web.ViewModel.CampusWebService.ExpenseAccount[]”隐式转换为“System.Collections.Generic.List”
EF 中新创建的类
[DataContract(IsReference = true)]
[KnownType(typeof(AccountCategoryMajor))]
[KnownType(typeof(ActivityReport))]
[XmlInclude(typeof(AccountCategory))]
public class AccountCategory : BaseEntity
{
[DataMember]
public long AccountcategoryMinnorID { get; set; }
[DataMember]
public virtual List<AccountCategoryMinnor> AccountCategoryMinnors { get; set; }
[DataMember]
public long ExpenseID { get; set; }
[DataMember]
public virtual Expense expense { get; set; }
}
当我删除我新创建的类实体时,它开始正常工作。我不知道它正在发生。
我什至能够单独运行 Wcf 服务,甚至在后端获得实体关系。
提前致谢。
【问题讨论】:
-
您可以在消费时将
Array转换为List,使用ToList()方法。
标签: c# asp.net-mvc entity-framework wcf