Single in LLBL like in Linq to Sql

Posts   
 
    
Posts: 15
Joined: 09-Oct-2008
# Posted on: 03-Nov-2008 03:07:59   

Any reason why this statement is working in Linq and not in Linq To LLBLGen


Dim md As New LinqMetaData()
Dim P As PersonEntity = md.Perons.Single(Function(o) o.First = "Mario" And o.Last = "Rossi")

Insteda this one work in both:


Dim md As New LinqMetaData()
Dim P As PersonEntity = md.Perons.Single(Function(o) o.First = "Mario")

Can I use the And statement in a .Single construct like in Linq to SQL?

Thanks.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 03-Nov-2008 09:30:35   
Frans Bouma | Lead developer LLBLGen Pro
Posts: 15
Joined: 09-Oct-2008
# Posted on: 03-Nov-2008 11:51:32   

Version 2.6 Final 12 September 2008

Using Linq to SQL no prob.

Using LLBL i get: An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as "" or [] are not allowed. Add a name or single space as the alias name.

That seems like if with the And construct in .Single the LLBL has built a "wrong" SELECT.

md.Perons.Single(Function(o) o.First = "Mario" And o.Last = "Rossi")

the problem is very easy to reproduce.

Anyway I have also attached the stack

Attachments
Filename File size Added on Approval
Stack.txt 4,650 03-Nov-2008 11:51.53 Approved
DvK
User
Posts: 318
Joined: 22-Mar-2006
# Posted on: 03-Nov-2008 12:45:39   
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 03-Nov-2008 14:18:55   

This was fixed on October 17th. The fix isn't out yet, but you can get the latest build with that fix from this message: http://www.llblgen.com/TinyForum/GotoMessage.aspx?MessageID=81455&ThreadID=14606

Frans Bouma | Lead developer LLBLGen Pro
Posts: 15
Joined: 09-Oct-2008
# Posted on: 03-Nov-2008 14:34:31   

Thanks, I will try an let You Know.

Posts: 15
Joined: 09-Oct-2008
# Posted on: 03-Nov-2008 15:12:40   

No, The problem is the same...

The best I was able to do is to build a small solution You will find: 1) the dal project LLBLGen Fiel 2) A solution with two projs: the Dal and the test App. 3) A small MDF file to attach to Your SQL 4) 3 lines of code wink

I have moved the dll to a different file.zip named bin to take less space on the attachments. (to be copied on both Dal and App bin folders)

You will need to change the PW to your server pw on the config file..

Please let me knwon, Thanks.

Posts: 15
Joined: 09-Oct-2008
# Posted on: 03-Nov-2008 15:41:09   

Just to confirm that wih Linq to SQL is working...


      Dim Md As New LinqMetaData()
      Dim Db As New DataClasses1DataContext

      ' Working LLBLGen
      ' Dim A As PersonEntity = md.Person.Single(Function(o) o.Name = "Mario Rossi")

      ' Working with Linq to SQL
      ' Dim A As Person = Db.Person.Single(Function(o) o.Name = "Mario Rossi" And o.DateOfBirth > #1/1/1950#)

      ' Not working in LLBLGen! (With And...)
      Dim A As PersonEntity = Md.Person.Single(Function(o) o.Name = "Mario Rossi" And o.DateOfBirth > #1/1/1950#)

      With Me.DataGridView1
          .DataSource = A.Dog
      End With

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 03-Nov-2008 18:07:48   

Will look into it.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 04-Nov-2008 13:56:52   

The 'And' is converted by the vb.net compiler in a bitwise Expression type 'And', you should use AndAlso instead of 'And' in these kind of predicates.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 15
Joined: 09-Oct-2008
# Posted on: 04-Nov-2008 14:59:03   

Not working, even with AndAlso, You can try on the solution I posted changing the code to:


Dim A As PersonEntity = Md.Person.Single(Function(o) o.Name = "Mario Rossi" AndAlso o.DateOfBirth > #1/1/1950#)

... for me same result.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 04-Nov-2008 15:19:46   

Antonio wrote:

Not working, even with AndAlso, You can try on the solution I posted changing the code to:


Dim A As PersonEntity = Md.Person.Single(Function(o) o.Name = "Mario Rossi" AndAlso o.DateOfBirth > #1/1/1950#)

... for me same result.

Hmm... works in C#, will see what the VB.NET specifics are of this... (as the VB.NET compiler sometimes creates different expression trees)

Frans Bouma | Lead developer LLBLGen Pro
Posts: 15
Joined: 09-Oct-2008
# Posted on: 04-Nov-2008 16:18:02   

I confirm in c# is Working:


LinqMetaData Md = new LinqMetaData();
DateTime D = new DateTime(1950, 1, 1, 0, 0, 0);
PersonEntity A = Md.Person.Single(o => o.Name == "Mario Rossi" && o.DateOfBirth.Value > D);
dataGridView1.DataSource = A.Dog;

... as You have said only with && .... but in VB with AndAlso is not working anyway.

... bha!!!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 04-Nov-2008 17:55:23   

Antonio wrote:

I confirm in c# is Working:


LinqMetaData Md = new LinqMetaData();
DateTime D = new DateTime(1950, 1, 1, 0, 0, 0);
PersonEntity A = Md.Person.Single(o => o.Name == "Mario Rossi" && o.DateOfBirth.Value > D);
dataGridView1.DataSource = A.Dog;

... as You have said only with && .... but in VB with AndAlso is not working anyway.

... bha!!!

With VB.NET:


<Test()> _
    Public Sub SimpleSingleCallWithMultiplePredicatesUsingAnd()
        Using adapter As New DataAccessAdapter()
            Dim metaData As New LinqMetaData(adapter)
            Dim q = metaData.Customer.Single(Function(c) c.CustomerId = "CHOPS" AndAlso c.Country = "Switserland")
            Assert.IsNotNull(q)
        End Using
    End Sub

Works OK. confused

With 'And' it doesn't. (It is hard to determine what the user wants in that case with the expression tree at hand, so please use AndAlso)

Be aware that 'Single' will throw an exception if 0 or 2 or more rows are returned, your query has to return exactly 1 row. That's how 'Single' is defined by Microsoft. It's IMHO not really a practical method. You can also use First() with the same filter, which doesn't throw an exception. So I'm interested in what exception you're getting with the build I pointed you to. (looking at your predicates, I can imagine more than 1 row or 0 rows are returned)

Frans Bouma | Lead developer LLBLGen Pro
Posts: 15
Joined: 09-Oct-2008
# Posted on: 04-Nov-2008 18:37:44   

Dear Frans,

No. As You can see from my previous posts... I have tried the same code in two ways...

Staight Linq to SQL and works... LLBL Gen Linq with && in C# and works...

With VB release 6Oct, DLL Linq support updated, Self Servicing and 'AndAlso'.... And non work!

'Mario Rossi' anyway returns only one row, as obvius from the above two statements... (Work in Linq To SQL and LLBLGEN C#)

I'm not so expert to give You the right debug infos... on LINQ... wink That's why i have done a little demo project and I have posted to You.

To debug You can just attach the little test database... copy the bin files... and run the project! .... and You will be, better than me able to trace the error.

Thanks. Antonio.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 04-Nov-2008 18:52:07   

Sorry for the delay, we always try to add a reprocase to our own tests so we keep it around.

I see that your case is different than the one I tested: you have a Nullable(Of T) type in the predicate. If you use: Dim A As PersonEntity = md.Person.Single(Function(o) o.Name = "Mario Rossi" AndAlso o.DateOfBirth.Value > #1/1/1950#)

instead of Dim A As PersonEntity = md.Person.Single(Function(o) o.Name = "Mario Rossi" AndAlso o.DateOfBirth > #1/1/1950#)

It works. The reason is explained here (Second Note box under 'Aggregates').

This is indeed unfortunate, however we were unable to provide proper code which always works for this particular situation.

This might sound like a lame excuse but the problem is that there is no documentation about what a compiler produces exactly, given a linq query, so it's for us, outside Microsoft, not clear what to expect in all situations, hence the workaround for this situation instead of a routine which does work properly for this particular situation.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 15
Joined: 09-Oct-2008
# Posted on: 05-Nov-2008 02:39:44   

My respect to all people who taking care of the work like You smile Thanks for all.