IEntityView2
inherits the non-generic interface IEnumerable
. The Select
method however needs the generic version. That's why you are getting the error.
Assuming that the properties you want to access are defined on IEntity2
, the following will work:
view.Cast<IEntity2>()
.Select(c => new A1AllocationHelp1TableDTO
{
RecordStatus = c.RecordStatus,
UniqueIdent = c.UniqueIdent
})
.ToList();
It works in VB.NET because it uses late binding. You can easily see this on the following sample:
Dim view As IEntityView2 = table.DefaultView
Dim something As List(Of A1AllocationHelp1TableDTO) = _
(From c In view
Select New A1AllocationHelp1TableDTO With _
{
.RecordStatus = c.IDontExist _
}).ToList()
I am using a property that doesn't exist (IDontExist
). This code will still compile but throw an exception at runtime:
MissingMemberException: Public member 'IDontExist' on type 'IEntity2' not found.
at Microsoft.VisualBasic.CompilerServices.Symbols.Container.GetMembers(String& MemberName, Boolean ReportErrors)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.ObjectLateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)