How to use LINQ Query .Any function

How to use LINQ Query .Any function

Postby borisb » Sun 12 Feb 2017 02:10

The LINQ syntax guide says the Any function

Any clause returns True if the input sequence contains any elements, otherwise False


and shows the following example:

Code: Select all
Linq.From(Emp)
    .Select([Emp['EmpNo'], Emp['EName']])
    .Any(Emp['Sal'] >= 1000)


However, in the following code:

Code: Select all
function TdmSecurityService.IsValidLogin(AUsername, APassword: string): boolean;
var
  Context: TDQCLabManagerDataContext;
  Users: IUserEntityExpression;

begin
  Context := dmDatabaseService.CreateContext;
  Users := Context.UserEntity;

  Result := Linq.From(Users)
    .Select
    .Any(
      (Users['Username'] = AUserName)
      AND
      (Users[Context.Model.UserEntity.Password.Name] = APassword ));
end;


Gives a compile error:

[dcc64 Error] D_SecurityService.pas(48): E2010 Incompatible types: 'Boolean' and 'ILinqQueryable'


What's wrong?
borisb
 
Posts: 4
Joined: Mon 12 Sep 2016 12:22

Re: How to use LINQ Query .Any function

Postby AlexP » Fri 17 Feb 2017 09:58

Hello,

Please provide the model file to support*devart*com, in order for us to be able to reproduce the problem.
AlexP
Devart Team
 
Posts: 5500
Joined: Tue 10 Aug 2010 11:35

Re: How to use LINQ Query .Any function

Postby borisb » Fri 17 Feb 2017 21:00

It has nothing to do with the model :-)

The problem is that .Any (like .Count) returns an ILinqQueryable instead of a boolean (or int in the case of .Count).

Can you send me a sample project instead that demonstrates that calling .Any returns a boolean...?
borisb
 
Posts: 4
Joined: Mon 12 Sep 2016 12:22


Return to EntityDAC