Why isn't DbSet covariant?
问题 I have a factory function to return a DbSet(Of IItemType) . The actual return type will always be an implementation IItemType , for example DbSet(Of CategoryType) . I thought covariance is supported in generics and this method would work fine, but I get an exception when I try to run my code: Unable to cast object of type 'System.Data.Entity.DbSet 1[CategoryType]' to type 'System.Data.Entity.DbSet 1[IItemType]'. 回答1: It looks like they could be covariant. But there is a host of differences