views:

147

answers:

0

Hi, everyone. I am getting a error with following code (C# with SubSonic 3)

(Korisnik == User && Uloga == Role)

            dbPupinDB db = new dbPupinDB();

        SqlQuery query = db
        .SelectColumns( 
            KorisnikTable.IdKorisnikColumn,
            KorisnikTable.UsernameColumn,
            KorisnikTable.EmailColumn )
        .From<Korisnik>();

        if( !String.IsNullOrEmpty(filterUsername) )
            query = query.Where(KorisnikTable.UsernameColumn).StartsWith(filterUsername);

        if( filterUloga.HasValue )
            query = query.InnerJoin<KorisnikImaUlogu>().Where(KorisnikImaUloguTable.IdUlogaColumn).IsEqualTo(filterUloga.Value);

        int totalRecords = query.GetRecordCount();

As you can see, I am trying to filter data based on two inputs. First is username, which works, but after I add filterUloga, I got the error about WHERE clause. Here is the generated SQL statement:

{SELECT [dbo].[Korisnik].[IdKorisnik], [dbo].[Korisnik].[Username], [dbo].[Korisnik].[Email]
FROM [dbo].[Korisnik]
INNER JOIN [dbo].[KorisnikImaUlogu] ON [dbo].[Korisnik].[IdKorisnik] = [dbo].[KorisnikImaUlogu].[IdKorisnik]
WHERE [dbo].[Korisnik].[Username] LIKE @0 WHERE [dbo].[KorisnikImaUlogu].[IdUloga] = @1}

As You can see the problem is that TWO where clauses are generated. I saw the AND functions but don't know how to use them.

Thanks for help!