【问题标题】:Entity Framework - passing different object sets as a parameter in a function实体框架 - 将不同的对象集作为函数中的参数传递
【发布时间】:2012-04-11 11:19:06
【问题描述】:

我有以下代码:

Private Sub setDropdowns()
    Using licensingModel As New licensingEntities
        SetUpDropdowns(licensingModel.tblLookup_Country, "CountryName", "CountryName", country)
        SetUpDropdowns(licensingModel.tblLookup_Country, "CountryName", "CountryName", bizCountry)
        SetUpDropdowns(licensingModel.tblLookup_Salutation, "SSalutation", "SSalutation", salutation)
        SetUpDropdowns(licensingModel.tblLookup_OrgType, "OrgType", "OTAuto", organisationType)
    End Using
End Sub

和子SetUpDropdowns:

Private Sub SetUpDropdowns(ByVal entity As IObjectSet(Of EntityObject), ByVal textColumn As String, ByVal valueColumn As String, ByVal combo As RadComboBox)
    combo.DataSource = entity
    combo.DataBind()
End Sub

我的问题是我不知道如何为 sub 定义参数类型。因为它们是每次传递的不同类型的对象集,我认为IObjectSet(Of EntityObject) 会起作用,但它给了我以下错误:

无法转换类型为“System.Data.Objects.ObjectSet1[licensingModel.tblLookup_Country]' to type 'System.Data.Objects.IObjectSet1[System.Data.Objects.DataClasses.EntityObject]”的对象‌

有人能解决这个问题吗?

【问题讨论】:

  • 这是错误顺便说一句:无法转换类型为“System.Data.Objects.ObjectSet1[licensingModel.tblLookup_Country]' to type 'System.Data.Objects.IObjectSet1[System.Data.Objects.DataClasses.EntityObject]”的对象。
  • 欢迎来到 SO,第一个问题 +1。
  • 你试过定义泛型方法吗?
  • 我可以使用泛型。但我认为我可以使用我在上面尝试的其他方法,因为我认为它会更好?

标签: asp.net vb.net entity-framework


【解决方案1】:

你不能只使用对象作为参数吗?

【讨论】:

  • 我想我可以 :) 只是不太好。但我可能会这样做,谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-29
  • 1970-01-01
  • 2018-02-23
  • 2012-05-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多