所以我正在使用实体框架,我之前用ado.net编写了一个函数来获取两个值,然后返回一个数据表,我做了一些操作。 代码在下面
Protected Sub ddlFieldMappingProfile_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlFieldMappingProfile.SelectedIndexChanged
If ddlFieldMappingProfile.SelectedValue >= 0 Then
btnImportData.Enabled = True
End If
If ddlFieldMappingProfile.SelectedValue <= 0 Then Return
Dim lstHeaders As List(Of String)
Dim dtMapping As New DataTable()
Dim intCount As Integer = 0
Try
Using com As New Common
With com
dtMapping = .getProfileFields(Convert.ToInt32(ddlFieldMappingProfile.SelectedValue))
IEMapping = .getProfileFields(Convert.ToInt32(ddlFieldMappingProfile.SelectedValue))
lstHeaders = .FileHeaders(FileUpl.FiletoRead, FileUpl.Delimiter)
End With
End Using
dtMapping.Columns.Add("MatchIndex")
For Each row As DataRow In dtMapping.Rows
For intCount = 0 To lstHeaders.Count() - 1
If lstHeaders(intCount) = row.Item("Dump_FieldName") Then
row.Item("MatchIndex") = intCount
Exit For
Else
row.Item("MatchIndex") = -1
End If
Next
Next
gdvFieldData.DataSource = dtMapping
gdvFieldData.DataBind()
gdvFieldData.Visible = True
Catch ex As Exception
Throw ex
Finally
dtMapping.Dispose()
lstHeaders = Nothing
End Try
End Sub
But now that I am using entity frame work I have written the LINQ query like
Dim Context As New ICOM_Model.IcomsEntities()
Dim query = From F In Context.Incentive_Prepaid_FieldMapping Where F.Profile_ID = Profile_ID
Select New With {.Activations_FieldName = F.Activations_FieldName, .Dump_FieldName = F.Dump_FieldName}
匿名类型。 请帮助我什么是返回类型以及我将如何在代码中操作ddlFieldMappingProfile_SelectedIndexChanged
答案 0 :(得分:0)
在您的代码中,返回类型将是匿名的,具有两个属性“Activations_FieldName和Dump_FieldName”,您可以通过“query”对象访问该值。
您可以创建一个具有您按实体选择的属性的类,并填充该类对象。
class ABC{
string Activations_FieldName{get;set;}
string Dump_FieldName{get;set;}
}
Dim Context As New ICOM_Model.IcomsEntities()
List<ABC> query = From F In Context.Incentive_Prepaid_FieldMapping Where F.Profile_ID = Profile_ID
Select New ABC With {.Activations_FieldName = F.Activations_FieldName, .Dump_FieldName = F.Dump_FieldName}
现在您可以在代码中使用此类对象。希望这有帮助。