lambda expression invalide
Bonjour,
J'aurai besoin d'un peu d'aide car je tourne en rond depuis 2 jours.
J'ai un tableau de type:
Code:
1 2
|
public BillingServices.InvoiceSetDetail[] isdList; |
pour info:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
public partial class InvoiceSetDetail {
private string serviceProviderField;
private string invoiceNumberField;
private string accountRefField;
private string accountNameField;
private string invoiceStyleField;
private Invoice hDInvoiceField;
private string filePathField;
private string fileNameField;
private bool isPrintedField;
private STATUS statusIDField;
private int pdfNbPagesField;
private int pdfNbPagesMemoField;
[...]
} |
sur lequel je peux appliquer 3 filtres:
Sur l'AccountName, l'AccountRef et l'InvoiceStyle.
Les 2 premiers sont des champs saisissables et le 3eme une combo.
J'aimerai donc creer mon expression en fonction de ces filtres pour avoir:
Code:
1 2 3
|
Func<BillingServices.InvoiceSetDetail, bool> expression = GenerateAttributesDescriptionBillingToLinq(filterOptions);
IEnumerable<BillingServices.InvoiceSetDetail> test = isdList.Where(expression); |
1er probleme: test est soit nul, soit me renvoie tout... j'ai essayé pas mal de chose...
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
private Func<BillingServices.InvoiceSetDetail, bool> GenerateAttributesDescriptionBillingToLinq(List<FilterOption> filterOptions)
{
Expression<Func<BillingServices.InvoiceSetDetail, bool>> expression = null;
Expression<Func<BillingServices.InvoiceSetDetail, bool>> search1;
Expression<Func<BillingServices.InvoiceSetDetail, bool>> search2;
Expression<Func<BillingServices.InvoiceSetDetail, bool>> search3;
foreach (FilterOption filterOption in filterOptions)
{
if ((filterOption.Type == typeof(string) && filterOption.Value == null) || filterOption.Value != "")
{
if (filterOption.Name == "AccountName" && !string.IsNullOrEmpty(filterOption.Value))
{
search1 = i => i.AccountName.Contains(filterOption.Value.ToString());
expression = search1;
}
if (filterOption.Name == "BUYER_ID" && !string.IsNullOrEmpty(filterOption.Value))
{
search2 = i => i.AccountRef.Contains(filterOption.Value.ToString());
if (expression.Body != null)
expression = Expression.Lambda<Func<BillingServices.InvoiceSetDetail, bool>>(Expression.And(expression.Body, search2.Body), expression.Parameters[0]);
else
expression = search2;
}
if (filterOption.Name == "InvoiceStyle" && !string.IsNullOrEmpty(filterOption.Value))
{
search3 = i => i.InvoiceStyle.Contains(filterOption.Value.ToString());
if (expression.Body != null)
expression = Expression.Lambda<Func<BillingServices.InvoiceSetDetail, bool>>(Expression.And(expression.Body, search3.Body), expression.Parameters[0]);
else
expression = search3;
}
}
}
return expression.Compile();
} |
Et 2eme pb, comment je recharge mon tableau trié depuis ma liste IEnumerable<>
Merci merci pour toute aide :)