【问题标题】:omit metdata from ef context for breeze为微风从 ef 上下文中省略元数据
【发布时间】:2013-01-23 06:34:34
【问题描述】:

我正在使用微风.js webapi 来公开下面的类。我了解不支持 DbGeography 类型,因此我使用 JsonIgnore 从输出中将其删除,但如何使其从元数据中被忽略/省略?

Public Class Household
<Key>
Public Property Id As Integer
Public Property Postcode As String
Public Property Saving As Decimal
<JsonIgnore>
Public Property Coordinates As DbGeography
Public ReadOnly Property Latitude As Double
    Get
        Return Coordinates.Latitude.Value
    End Get
End Property
Public ReadOnly Property Longitude As Double
    Get
        Return Coordinates.Longitude.Value
    End Get
End Property
End Class

<BreezeController>
Public Class HouseholdsController
Inherits ApiController

Private ReadOnly _contextProviders As EFContextProvider(Of EnergyFriendContext) = New     EFContextProvider(Of EnergyFriendContext)

' ~/api/Households/Metadata 
<HttpGet>
Public Function Metadata() As String
    Return _contextProviders.Metadata()
End Function

' ~/api/Households/Households
' ~/api/Households/Households?$filter=IsArchived eq false&$orderby=CreatedAt
<HttpGet>
Public Function Households() As IQueryable(Of Household)
    Return _contextProviders.Context.Households
End Function

End Class

微风js错误:

Unable to recognize DataType for: Edm.Geography 

【问题讨论】:

    标签: javascript vb.net asp.net-web-api breeze


    【解决方案1】:

    好的,从 1.1.1 版开始,当遇到“未知”数据类型时,微风将不再抛出此异常。

    具有“未知”数据类型的数据属性现在将出现在 DataType 为“未定义”的 EntityType 元数据中。

    从服务器返回的任何“未定义”数据类型的数据现在将通过原始数据传递,这意味着数据将完全是在服务器上序列化的数据,无需任何轻量处理。

    目前包括 DbGeometry 和 DbGeography 类。

    现在可以从 EntityType.dataProperties 属性返回的数组中删除单个数据属性。

    删除一个属性告诉微风,当返回给客户端时,这个属性不应该被具体化到任何这种类型的实体上。这允许客户端有效地忽略任何服务器端属性的数据。

    注意:忽略一个属性时可能需要确保它不会被服务器序列化。我认为你已经在这样做了。

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-29
      • 1970-01-01
      • 2018-07-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多