Bonjour J'ai des problèmes avec un arbre d'expression utilisant la méthode d'extension .Any().Linq Expression tree Any() issue
Voici mon code:
IQueryable<Book> querableBooks = Books.Values.AsQueryable<Book>();
ParameterExpression pe = Expression.Parameter(typeof(Book), "book");
MemberExpression props = Expression.Property(pe, "properties");
ParameterExpression propList = Expression.Parameter(typeof(List<BookProperty>), "properties");
var _test = Expression.Lambda<Func<List<BookProperty>, bool>>(operation, new ParameterExpression[] { propList });
var _Any = Expression.Call(typeof(Enumerable), "any", new Type[] { typeof(BookProperty) }, new Expression[] { propList });
Expression Lamba = Expression.Lambda(_Any, _props);
_Test renvoie {propriétés => ((bookProperty.type.key == "lingerie") et (bookProperty.value == "1"))}
retours _any {properties.Any()}
retours Lambda
{book.properties => properties.Any()} La classe livre est comme ceci:
public class Book : IBook
{
public int id { get; set; }
//Removed for clarity
public List<BookProperty> properties { get; set; }
}
Une classe BookProperty:
public class BookProperty
{
public BookProperty()
{
value = "0";
}
public int id { get; set; }
public int bookId { get; set; }
public Book book { get; set; }
public int typeId { get; set; }
public BookPropertyType type { get; set; }
public string value { get; set; }
}
Et classe BookPropertyType:
public class BookPropertyType
{
public int id { get; set; }
public string groupe { get; set; }
public string key { get; set; }
public string label { get; set; }
public int order { get; set; }
public string editorType { get; set; }
public string unite { get; set; }
}
Je suis proche, mais je ne sais pas comment fusionner correctement tout cela pour avoir un requête comme celle-ci
{book.propertie.Any (bookProperty => bookProperty.type.key == "lingerie") Et (bookProperty.value == "1")}
Merci pour votre aide.
Il serait utile si vous incluez la 'Book' et Classes 'BookProperty'. –
@IvanStoev J'ai ajouté les classes. Merci – Julien
cherchez-vous à obtenir un sous-ensemble des livres interrogeables en fonction du type de propriété et de la valeur de la propriété? Si oui, qu'en est-il de: queryableBooks.Where (book => book.properties.Any (propriété => property.type.key == "lingerie" && property.value == "1")) – Brino