Filtering on boolean properties

Posts   
 
    
Jez
User
Posts: 198
Joined: 01-May-2006
# Posted on: 13-Mar-2008 14:55:29   

I've run into a slight problem when filtering on a boolean property (adapter, SQL 2005).

I have this query:


metaData.
    Where(s => s.StudentRef == studentRef && s.Submitted);

Which generates this invalid SQL:

exec sp_executesql N'SELECT DISTINCT [LPLA_1].[Id], [LPLA_1].[Student_Ref] AS [StudentRef], [LPLA_1].[Subject_Code] AS [SubjectCode], [LPLA_1].[Subject_Group] AS [SubjectGroup], [LPLA_1].[Submitted], [LPLA_1].[Reference] FROM [Cristal].[dbo].[Subject_References] [LPLA_1]  WHERE ( ( ( ( ( ( [LPLA_1].[Student_Ref] = @StudentRef1) AND ( [LPLA_1].[Submitted]))))))',N'@StudentRef1 int,@Submitted2 bit',@StudentRef1=20063002,@Submitted2=1

I would have expected the predicte for submitted to be generated as AND [LPLA_1].[Submitted] = @Submitted2

I'm currently getting round the issue by doing this:

metaData.Where(s => s.StudentRef == studentRef && Convert.ToInt32(s.Submitted) == 1)
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 13-Mar-2008 15:10:18   

PLease post the full code. I can't see what 'metadata' is and therefore I can't setup a repro case.

Frans Bouma | Lead developer LLBLGen Pro
Jez
User
Posts: 198
Joined: 01-May-2006
# Posted on: 13-Mar-2008 15:29:10   

Sorry about that.

Here's the code in full:


[Test]
public void Test1()
{
    int studentRef = 20063002;
    using (DataAccessAdapter adapter = new DataAccessAdapter())
    {
        var metaData = new LinqMetaData(adapter).SubjectReference;
        var results = metaData.Where(s => s.StudentRef == studentRef && s.Submitted).ToList();
    }
}

Here's the DDL for the table if you need it:


CREATE TABLE [dbo].[Subject_References](
      [Id] [int] IDENTITY(1,1) NOT NULL,
      [Student_Ref] [int] NOT NULL,
      [Subject_Code] [nvarchar](10) NOT NULL,
      [Subject_Group] [nvarchar](2) NULL,
      [Submitted] [bit] NOT NULL,
      [Reference] [varchar](max) NULL,
 CONSTRAINT [PK_Subject_References] PRIMARY KEY CLUSTERED 
(
      [Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]


Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 13-Mar-2008 16:11:46   

Ah thanks, it's a table simple_smile

I can repro this with a northwind query:

using(DataAccessAdapter adapter = new DataAccessAdapter())
{
    LinqMetaData metaData = new LinqMetaData(adapter);
    var q = from p in metaData.Product
            where p.SupplierId == 5 && p.Discontinued
            select p;

    int count = 0;
    foreach(var v in q)
    {
        Assert.IsTrue(v.Discontinued);
        Assert.AreEqual(5, v.SupplierId);
        count++;
    }
    Assert.AreEqual(2, count);
}

Looking into it.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 13-Mar-2008 18:36:46   

Fixed in next build.

Frans Bouma | Lead developer LLBLGen Pro