Julie Lerman

I downloaded the C# samples from CodePlex , but am trying to check previously written VB code that works in Beta1.

A very simple example using our old standby northwind is:

Code Snippet
Dim orders = _
From o In NWEntities.Orders _
Select o Where o.Customers.Country = "Spain"

When trying to create any similar query in the CTP (on Windows XP by the way), the compiler says that the query is bad.

Overload resolution failed becasue no accessible "select" can be called with these arguments

Then a long list of extension methods is listed with complaints about bad signatures, type parameters not being inferred etc.

I've looked at the queries in the help file that got installed with the CTP and tried emulating them, but that fails as well.

So has LINQ changed that much Or is this something specific to LINQ to Entities Is my error expected because that is no longer a valid query or is there something else wrong

Thanks



Re: ADO.NET (Pre-release) June CTP - Linq to Entities in VB?

Colin Meek - Microsoft

There is a known issue preventing overload resolution for LINQ to Entities queries in VB. The Beta 2 VB compiler includes a fix.

The workaround is to explicitly treat the source query as an IQueryable instance, e.g.

Dim scan As IQueryable(Of Order) = NWEntities.Orders

Dim orders = _

From o In scan _

Select o Where o.Customers.Country = "Spain"

Thanks,

-Colin






Re: ADO.NET (Pre-release) June CTP - Linq to Entities in VB?

Julie Lerman

Okay, that works.





Re: ADO.NET (Pre-release) June CTP - Linq to Entities in VB?

Roger Jennings

Julie,

Public Sub GetLastTenOrdersFromMexico()

Dim Query = (From o In nwContext.Orders _

Where o.Customer.Country = "Mexico" _

Order By o.OrderID Descending _

Select o.OrderID, o.Customer.CustomerID, o.Employee.EmployeeID, _

o.OrderDate, o.ShippedDate).Take(10)

ObjectDumper.Write(Query)

End Sub

works fine for me (as does Select o) without the explicit IQueryable cast.

--rj





Re: ADO.NET (Pre-release) June CTP - Linq to Entities in VB?

Julie Lerman

Oh, that's just not fair! . I wonder if you have some imports statements in your code that I don't have



Re: ADO.NET (Pre-release) June CTP - Linq to Entities in VB?

Roger Jennings

Julie,

Here are the imports:

Imports System

Imports System.Data

Imports System.Configuration

Imports System.Collections

Imports System.Linq

Imports System.Web

Imports System.Web.Security

Imports System.Web.UI

Imports System.Web.UI.WebControls

Imports System.Web.UI.WebControls.WebParts

Imports System.Web.UI.HtmlControls

Imports System.Diagnostics

Nothing special; System.Diagnostics is there for Stopwatch.

In a few minutes, an ObjectQuery example will be added to the Entity Framework June 2007 CTP Visual Basic Samples post.

--rj





Re: ADO.NET (Pre-release) June CTP - Linq to Entities in VB?

Julie Lerman

I did a clean install on a clean CTP and it now works properly. I don't have to create the IQueryable.