我在MVC 3
应用程序中使用Entity Framework 4.1 code first
。无法将类型System.Data.Entity.DbSet转换为System.Collections.Generic.ICollection
我有以下的库:
public class BankRepository : IBankRepository
{
HefContext db = new HefContext();
public ICollection<Bank> GetAll()
{
return db.Banks;
}
}
返回db.Banks当我得到一个错误。我不知道这意味着什么,有人可以帮助澄清,以及如何使错误消失改变呢?错误是:
Cannot implicitly convert type 'System.Data.Entity.DbSet<MyProject.Core.DomainObjects.Bank>' to 'System.Collections.Generic.ICollection<MyProject.Core.DomainObjects.Bank>'. An explicit conversion exists (are you missing a cast?)
什么是db.Banks回来了?一个IEnumerable?
大多数例子在线使用的ICollection的?为什么是这样? –
@Brendan情况必须是在这些例子不同,因为您的代码不编译。 – Eranga