左加入Linq到实体的Vb.net [英] Left Join Linq to Entity's Vb.net
问题描述
我无法弄清楚linq to实体查询语法.我的问题是,如果Calls表的值为null,那么就会出现提示,我想进行类似于左联接的操作,以从Calls表中获取所有"行.
I can't figure out that linq to entity query syntax. My problem is that if the value of the Calls table is null then noting comes up, I want to make something like a left join to get 'all' rows from the Calls table.
我尝试将其分组,但是我找不到正确的编写方式.
I tried to group it but I can't figure out the correct way to write it.
Dim TicketQuery As ObjectQuery = From c In EnData.Customer _
Join t In EnData.Calls On t.CustomerID Equals c.CustomerID _
Join Status In EnData.Lists On t.Status Equals Status.ListValue _
Join Project In EnData.Lists On t.Project Equals Project.ListValue _
Join Priorty In EnData.Lists On t.Priority Equals Priorty.ListValue _
Where c.Status > -1 And t.Status > -1 And Status.ListType = 1 And Project.ListType = 3 And Priorty.ListType = 2 _
Select New With {c.CustName, t.CallID, t.CallDate, t.CallTime, t.Description, Key .Status = Status.ListText, Key .Project = Project.ListText, t.DateModified, Key .Priority = Priorty.ListText}
我该如何解决?
推荐答案
类似的问题: Microsoft文档: http://msdn.microsoft.com/en -us/library/bb918093.aspx#Y916
Microsoft Documentation: http://msdn.microsoft.com/en-us/library/bb918093.aspx#Y916
LINQ示例来自: http://msdn.microsoft.com/zh-cn/vbasic/bb737909
LINQ Examples from: http://msdn.microsoft.com/en-us/vbasic/bb737909
左外部联接 所谓的外部联接可以用组联接来表示.左外部连接类似于交叉连接,除了所有左侧元素至少包含一次,即使它们与任何右侧元素都不匹配也是如此.请注意,即使没有匹配的产品,蔬菜也将显示在输出中.
Left Outer Join A so-called outer join can be expressed with a group join. A left outer joinis like a cross join, except that all the left hand side elements get included at least once, even if they don't match any right hand side elements. Note how Vegetables shows up in the output even though it has no matching products.
Public Sub Linq105()
Dim categories() = {"Beverages", "Condiments", "Vegetables", "Dairy Products", "Seafood"}
Dim productList = GetProductList()
Dim query = From c In categories _
Group Join p In productList On c Equals p.Category Into Group _
From p In Group.DefaultIfEmpty() _
Select Category = c, ProductName = If(p Is Nothing, "(No products)", p.ProductName)
For Each v In query
Console.WriteLine(v.ProductName + ": " + v.Category)
Next
End Sub
这篇关于左加入Linq到实体的Vb.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!