我创建了一个Visual Basic WPF应用程序项目,其中包含Toy.edmx,这是一个从名为Toy的数据库生成的ADO.NET实体数据模型.
它的Window1.xaml.vb文件如下所示:
1 Class Window1 2 3 Private Sub Window1_Loaded( _ 4 ByVal sender As System.Object, _ 5 ByVal e As System.Windows.RoutedEventArgs) _ 6 Handles MyBase.Loaded 7 8 Dim dc As New ToyEntities1 9 Label1.Content = (From c As Client In dc.ClientSet _ 10 Select c).First.FirstName 11 12 End Sub 13 14 End Class
运行得很好.
但是,如果我添加文件Client.vb ...
1 Partial Public Class Client 2 Function IsWashington() As Boolean 3 Return Me.LastName = "Washington" 4 End Function 5 End Class
...并在我的Window1.xaml.vb查询中添加WHERE子句...
9 Label1.Content = (From c As Client In dc.ClientSet _ 10 Where c.IsWashington _ 11 Select c).First.FirstName
...然后我得到这个NotSupportedException:
LINQ to Entities无法识别方法'Boolean IsWashington()'方法,并且此方法无法转换为存储表达式.
如何使用分部类扩展ADO.NET实体框架对象?