Domanda

Sto provando a testare un metodo Async in EF 6.0.2 con MOQ 4.0.10827 e mi viene bloccato in ciò che sembra essere un problema di casting.

Le seguenti opere Fine:

public async Task<List<Testimonial>> GetByEventIdAsync(int eventId)
{
    var query = from t in _context.Testimonials
                orderby t.Ordinal
                select t;
    var result = query
        .ToListAsync()
        .ConfigureAwait(false);
    return await result;
}
.

Ma le seguenti interruzioni (aggiunte una clausola dove)

public async Task<List<Testimonial>> GetByEventIdAsync(int eventId)
{
    var query = from t in _context.Testimonials
                where t.EventId == eventId
                orderby t.Ordinal
                select t;
    var result = query
        .ToListAsync()
        .ConfigureAwait(false);
    return await result;
}
.

Ho fatto qualche debug e ho trovato il seguente

var q1 = _context.Testimonials; // Type = Castle.Proxies.IDbSet`1Proxy_1
var q2 = q1.Where(t => t.EventId == eventId); // Type = TestDbAsyncEnumerable`1 (from linked code)
var q3 = q2.OrderBy(o => o.Ordinal); // Type = System.Linq.EnumerableQuery`1
.

Perché la classe è la doppia scomparizione?E come lo aggiusta?

Aggiornamento: Ho anche scoperto che se aggiungo il retro del where e rimuovi il orderby, che funziona anche, quindi il problema sembra avere più clausole.

È stato utile?

Soluzione

Infine ha trovato la risposta qui.

IQueryable aveva bisogno di essere aggiunto come così:

public class TestDbAsyncEnumerable<T> 
    : EnumerableQuery<T>, IDbAsyncEnumerable<T>, IQueryable
.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top