Reputation: 11652
I am trying to assign results of vw_Source_Columns
to vw_UI_List_Search_Columns
in select statement. How to do in vb.net?
Partial Public Class vw_Source_Columns
Public Property Source As String
Public Property Field_Name As String
Public Property Field_Type As String
Public Property strSourceColumn As String
Public Property strSourceName As String
Public Property strDataViewName As String
Public Property intColumnID As Integer
Public Property intMaster As Integer
End Class
Public Class vw_UI_List_Search_Columns
Public Property Source As String
Public Property Field_Name As String
Public Property Field_Type As String
Public Property strSourceColumn As String
Public Property strSourceName As String
End Class
Dim query = From tblSources In writingEntities.vw_Source_Columns.AsNoTracking
query = query.Where(Function(tblSources) tblSources.strSourceName = tblName).OrderBy(Function(tblSources) tblSources.strSourceColumn)
'Dim lstfields As List(Of vw_UI_List_Source_Columns) = query.ToList()
'' assign query results of List (Of vw_UI_List_Source_Columns)
'' to List (Of vw_UI_List_Search_Columns) to suitable columns.
How to do this in vb.net? I use to do in c# by using new
keyword in select.
Upvotes: 0
Views: 639
Reputation: 6472
you must create an instance and set manually the properties like this:
Dim lstfields As List(Of vw_UI_List_Search_Columns)
lstfields = query.Select(Function(SourceItem) _
New vw_UI_List_Search_Columns() with _
{.Source = SourceItem.Source,
.Field_Name = SourceItem.Field_Name,
.Field_Type = SourceItem.Field_Type,
.strSourceColumn = SourceItem.strSourceColumn,
.strSourceName = SourceItem.strSourceName}).ToList()
If you were using inheritance, then class vw_Source_Columns
was heiress from vw_UI_List_Search_Columns
, You could do exactly the way you did (just in addition Cast(Of vw_UI_List_Search_Columns)
like this:
Public Class vw_Source_Columns
Inherits vw_UI_List_Search_Columns
Public Property strDataViewName As String
Public Property intColumnID As Integer
Public Property intMaster As Integer
End Class
Public Class vw_UI_List_Search_Columns
Public Property Source As String
Public Property Field_Name As String
Public Property Field_Type As String
Public Property strSourceColumn As String
Public Property strSourceName As String
End Class
Dim query = From tblSources In writingEntities.vw_Source_Columns.AsNoTracking
query = query.Where(Function(tblSources) tblSources.strSourceName = tblName).OrderBy(Function(tblSources) tblSources.strSourceColumn)
Dim lstfields As List(Of vw_UI_List_Source_Columns) = query.Cast(Of vw_UI_List_Search_Columns).ToList()
Upvotes: 1
Reputation: 4784
Dim lstfields As List(Of vw_UI_List_Search_Columns) = query.Select(Function(e) New vw_UI_List_Search_Columns With {.Source = e.Source, .Field_Name = e.Field_Name, etc...}).ToList()
Upvotes: 1