« LINQKit » : différence entre les versions
De Banane Atomic
Aller à la navigationAller à la recherche
Ligne 6 : | Ligne 6 : | ||
<kode lang='csharp'> | <kode lang='csharp'> | ||
Expression<Func<User, bool>> expression = x => x.Name.EndsWith("2"); | Expression<Func<User, bool>> expression = x => x.Name.EndsWith("2"); | ||
context.Users.Where(expression); // works fine ! | context.Users.Where(expression); // works fine ! | ||
// as x.Users is not a IQueryable, Any cannot take an Expression but a Func | |||
// so we need to use Compile to get Func from Expression | |||
context.Groups.Where(x => x.Users.Any(expression.Compile())); | |||
</kode> | </kode> |
Version du 14 mars 2021 à 11:00
Links
- LINQKit on GitHub
AsExpandable
Expression<Func<User, bool>> expression = x => x.Name.EndsWith("2"); context.Users.Where(expression); // works fine ! // as x.Users is not a IQueryable, Any cannot take an Expression but a Func // so we need to use Compile to get Func from Expression context.Groups.Where(x => x.Users.Any(expression.Compile())); |