使用Linq to Entities 3.5选择空列

时间:2011-08-10 21:13:07

标签: entity-framework asp.net-3.5

我正在使用 Entity Framework 3.5 。我的模型有一个Mediator表和一个MediatorAvailabilities表。大多数调解员在MediatorAvailabilities中没有条目(可用性=空)但我仍然需要带回调解员,无论是否存在相关的MediatorAvailabilities。

如果存在相关可用性,则下面的查询仅返回介体。同样,即使Availability = null,我如何获得调解器?:

Dim mediators = (From m In entity.Mediators.Include("MediatorAvailabilities") _
Where(m.MediatorAvailabilities.Any(Function(a) a.Availability = String.Empty Or a.Availability.Contains("Weekends") = True))
                         Where (m.isActive = True) _
                        Order By m.Sequence _
                        Select New RankingCriteria() With { _
                            .FirstName = m.FirstName, _
                            .LastName = m.LastName, _
                            .CompanyName = m.CompanyName, _
                            .PhoneHome = m.PhoneHome, _
                            .PhoneWork = m.PhoneWork, _
                            .PhoneMobile = m.PhoneMobile, _
                            .Email = m.Email _
                        }).ToList()

这样做的正确方法是什么?

1 个答案:

答案 0 :(得分:0)

我认为您需要在a.Availability is Nothing方法调用中添加Any,如下所示:

Where(m.MediatorAvailabilities.Any(Function(a) a.Availability is Nothing Or a.Availability = String.Empty Or a.Availability.Contains("Weekends") = True))