12 Ağustos 2017 Cumartesi

Entitiy Framework Where If Extension Method.

public static class Extension
{
public static IQueryable<TSource> WhereIf<TSource>(this IQueryable<TSource> source, bool condition, Expression<Func<TSource, bool>> predicate)
{
return condition ? source.Where(predicate) : source;
}
}

var query = db.USERS.WhereIf(txtName.Text.IsNotNull(), x => x.Name==txtName.Text).WhereIf(txtSurName.Text.IsNotNull(), x => x.SurName==txtSurName.Text);

 

 

Hiç yorum yok:

JavaScript

JavaScript Nedir?    JavaScript web tabanlı bir programlama dilidir. Mayıs 1995 yılında Brendan Eich tarafından tasarlanmıştır. Kullanıcı et...