.NET 3.5を使用しています。DataLayerクラスには、System.Core、System.Data.Linq、System.Data.DataSetExtensionsの参照があります。ただし、 Option Strictをオンにしている場合、Linqクエリでこの機能を使用することはできません。
Dim query = From st In db.Students _
From c In db.Countries.Where(Function(c) c.Id = st.CountryId).DefaultIfEmpty _
From r In db.Rooms.Where(Function(r) r.Id = st.RoomId).DefaultIfEmpty _
From b In db.Buildings.Where(Function(b) b.Id = r.BuildingId).DefaultIfEmpty _
From es In db.Essays.Where(Function(es) es.StudentId = st.Id).DefaultIfEmpty _
Select st.Id, st.FullName, c.CountryName, r.RoomNumber, b.BuildingName, es.Eassay
次のエラーが発生します。
Overload resolution failed because no accessible 'Where' can be called with these arguments:
Extension method 'Public Function Where(predicate As System.Linq.Expressions.Expression(Of System.Func(Of Country, Integer, Boolean))) As System.Linq.IQueryable(Of Country)'
defined in 'System.Linq.Queryable': Nested function does not have the same signature as delegate 'System.Func(Of Country, Integer, Boolean)'.
Extension method 'Public Function Where(predicate As System.Linq.Expressions.Expression(Of System.Func(Of Country, Boolean))) As System.Linq.IQueryable(Of Country)' defined in 'System.Linq.Queryable': Option Strict On disallows implicit conversions from 'Boolean?' to 'Boolean'.
Extension method 'Public Function Where(predicate As System.Func(Of Country, Integer, Boolean)) As System.Collections.Generic.IEnumerable(Of Country)' defined in 'System.Linq.Enumerable': Nested function does not have the same signature as delegate 'System.Func(Of Country, Integer, Boolean)'.
Extension method 'Public Function Where(predicate As System.Func(Of Country, Boolean)) As System.Collections.Generic.IEnumerable(Of Country)' defined in 'System.Linq.Enumerable': Option Strict On disallows implicit conversions from 'Boolean?' to 'Boolean'..........
「Where」句はSystem.Linq.Queryableのメンバーです
Public Shared Function Where(Of TSource)(ByVal source As System.Linq.IQueryable(Of TSource)、ByVal predicate As System.Linq.Expressions.Expression(Of System.Func(Of TSource、Boolean)))AsSystem.Linq。 IQueryable(Of TSource)
そして、「DefaultIfEmpty」はSystem.Linq.Queryableのメンバーです
パブリック共有関数DefaultIfEmpty(Of TSource)(ByVal source As System.Linq.IQueryable(Of TSource))As System.Linq.IQueryable(Of TSource)
Option Strict OFFに設定すれば、問題ありません。
Option Strict ONを使用してVB.NETプロジェクトでこれらのSystem.Linq拡張メソッドを使用するにはどうすればよいですか?ありがとうございました