Я определил следующие интерфейсы:Невозможно преобразовать IEnumerable <TEntity> в TCollection
public interface IReadOnlyRepositoryBase<TEntity, TKey, TCollection>
where TEntity : EntityBase<TKey>
where TCollection: IEnumerable<TEntity>
{
TCollection GetAll();
}
public interface IReadOnlyRepository<TEntity, TKey> :
IReadOnlyRepositoryBase<TEntity, TKey, IEnumerable<TEntity>>
where TEntity : EntityBase<TKey>
{ }
// there is also "ILazyReadOnlyRepository" where TCollection
// is IQueryable<T>..
Теперь я не могу вернуть IEnumerable<TEntity>
в моей реализации, потому что IEnumerable<TEntity>
не кажется, конвертируемые в TCollection
.
// basic repository impl for NHibernate
public abstract class NHibernateReadOnlyRepositoryBase<TEntity, TKey, TCollection>
: IReadOnlyRepositoryBase<TEntity, TKey, TCollection>
where TEntity : EntityBase<TKey>
where TCollection : IEnumerable<TEntity>
{
public TCollection GetAll()
{
// doesn't work...
return _session.QueryOver<TEntity>().List();
}
Насколько я могу видеть, метод возвращает IList<T>
, который реализует IEnumerable<T>
, так что это, очевидно, должно работать? Как я могу достичь того, чего хочу?
Как это должно работать? 'TCollection' также может быть' List ', в этом случае вы будете лить' IList 'на' Список '. Это невозможно. –