Pregunta

Tengo la siguiente clase TableServiceContext para los libros, quiero consultar los libros de mesa por el PartitionKey, por favor, ignora el hecho de que Estoy usando la clave de partición como el nombre del libro, esto es sólo para el bien de mis aprendizaje

   public class BookDataServiceContext: TableServiceContext
        {

            public BookDataServiceContext(string baseAddress, StorageCredentials credentials)
                : base(baseAddress, credentials)
            {
            }

            public IQueryable<Book> Books
            {
                get
                {
                    return this.CreateQuery<Book>("Books");
                }
            }

            public void AddMessage(string name, int value)
            {
                this.AddObject("Books", new Book {PartitionKey=name, BookName = name, BookValue = value});
                this.SaveChanges();
            }

            public Book GetBookByPartitionKey(Guid partitionKey)
            {
                var qResult = this.CreateQuery<Book>("Books");
    This doesnt work ---->           // qResult = qResult.Where(e => (e.PartitionKey.CompareTo(partitionKey)==0));

            } 
}

consigo un "No se puede convertir implícitamente el tipo 'System.Linq.IQueryable' a 'System.Data.Services.Client.DataServiceQuery'. Existe una conversión explícita (¿falta un yeso?)" En la última línea.

Cualquier ayuda será apreciada!

¿Fue útil?

Solución

qResult ya se ha asignado un tipo por el compilador. Usted está tratando de volver a asignar a un tipo diferente, pero que no está permitido.

Probar

var someOtherName = qResult.Where(e => (e.PartitionKey.CompareTo(partitionKey)==0));

Editar Parece que sus Libros propiedad es el tipo incorrecto

.
public DataServiceQuery<Book> Books
{
    get
    {
        return this.CreateQuery<Book>("Books");
    }
}

public Book GetBookByPartitionKey(string partitionKey)
{
    var qResult = Books.Where(e => (e.PartitionKey.CompareTo(partitionKey)==0));
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top