开发者

Subsonic3 LINQ Left Outer Join

I am using Subsonic3 and would like to get a Left Outer Join between two tables. Here is the tested SQL

SELECT a.* 
FROM vwVendor a
LEFT OUTER JOIN dbo.pubvenmap b
on a.vend_no = b.vend_no
where b.vend_no is null

I am stuck at

Dim vendors = From v In vwVendor.All()
Join m in pubvenmap.All() On v.vend_no Equals m.vend_no

UPDATED I also tried the following

Dim vendors = New SubSonic.Query.Select(SubSonic.Query.Aggregate.GroupBy("vend_no")).From(Of vwVendor).LeftOuterJoin(Of mac_pubvenmap)().ExecuteTypedList(Of vwVendor)()

but get the error

A first chance exception of type 'System.InvalidOpera开发者_C百科tionException' occurred in SubSonic.Core.dll

I am using Visual Studio 2010 and .NET 4.0...could this be the problem?


If the LINQ expression Albin posted gives you trouble (SubSonic's LINQ provider is not as complete as Linq2Sql or Entity Framework's), be aware that you can use SubSonic's fluent query objects to also perform a Left Outer Join:

SubSonic.SqlQuery query = new NorthwindDB.Select
  .From<Customer>()
  .LeftOuterJoin<Order>();
  query.Aggregates  = new List<Aggregate> { 
    new Aggregate(CustomerTable.CustomerNameColumn, AggregateFunction.GroupBy) };


All common LINQ constructs are examplified at LINQ 101 Samples. Specifically in this case Left Outer Join.

If I got my rusty VB right your code will be like this.

Dim vendors = From v In vwVendor.All() _
            Group Join m in pubvenmap.All() On v.vend_no Equals m.vend_no Into Group _
            From m In Group.DefaultIfEmpty() _
            Select v
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜