DocumentDB muestra todos los documentos del tipo de entidad específico
Tengo un @ genériIDocumentDbRepository
repositorio para proporcionar operaciones CRUD básicas con DocumentDB y repositorios específicos para operaciones adicionales con entidades específicas, que heredan o implementan esta interfaz y clase.
public interface IDocumentDbRepository<T> where T : class
{
//IEnumerable<T> GetItems();
Task<IEnumerable<T>> GetItemsAsync();
Task<T> GetItemAsync(T id);
Task<T> AddDocumentAsync(T item);
Task<T> UpdateDocumentAsync(T id, T item);
Task DeletedocumentAsync(T id);
}
public class DocumentDbRepository<T> : IDocumentDbRepository<T> where T : class
{
private readonly string AuthKey;
private readonly string EndpointUri;
private readonly string DatabaseId;
private readonly string CollectionId;
private static DocumentClient client;
public DocumentDbRepository(IOptions<DocumentDbSettings> DocumentDbConfig)
{
this.DatabaseId = DocumentDbConfig.Value.DatabaseName;
this.CollectionId = DocumentDbConfig.Value.CollectionName;
this.AuthKey = DocumentDbConfig.Value.AuthKey;
this.EndpointUri = DocumentDbConfig.Value.EndpointUri;
client = new DocumentClient(new Uri(EndpointUri), AuthKey);
}
public async Task<IEnumerable<T>> GetItemsAsync()
{
IDocumentQuery<T> query = client.CreateDocumentQuery<T>(
UriFactory.CreateDocumentCollectionUri(DatabaseId, CollectionId))
.AsDocumentQuery();
List<T> results = new List<T>();
while (query.HasMoreResults)
{
results.AddRange(await query.ExecuteNextAsync<T>());
}
return results;
}
// public IEnumerable<T> GetItems()
// {
// var results = client.CreateDocumentQuery<T>//(UriFactory.CreateDocumentCollectionUri(DatabaseId, CollectionId)).ToList();
// return results;
// }
//methods
En mi @ específiEmployee
repositorio Mi objetivo es devolver solo documentos de tipoEmployee
public interface IEmployeeRepository : IDocumentDbRepository<Employee>
{
List<Employee> GetAllEmployees();
}
public class EmployeeRepository : DocumentDbRepository<Employee>, IEmployeeRepository
{
public EmployeeRepository(IOptions<DocumentDbSettings> DocumentDbConfig) : base(DocumentDbConfig)
{
}
public List<Employee> GetAllEmployees()
{
return GetItems().Where(x => x.GetType() == typeof(Employee)).ToList();
}
}
Yo lo llamoGetAllEmployees
método en mi controlador para enumerar solo documentos de tipoEmployee
in my View, pero no funciona y todos los documentos con cualquier tipo de entidad se enumeran. Qué estoy haciendo mal
public IActionResult Index()
{
return View(_employeeRepository.GetAllEmployees());
}