无法使用计算属性创建查询... [英] Cannot create a query using a computed property...

查看:86
本文介绍了无法使用计算属性创建查询...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(对于LS团队)我发现我们无法使用实体的计算属性来定义查询。这是情况人员:我使用计算属性为我的属性"OrderRemarks"指定一个值。如下:Private Sub OrderRemarks_Compute(ByRef
result As String)'将结果设置为me.PurchaseOrderDetail.Lackings中每个d的所需字段值,如果d.lackings< = 0则then result =" Delivery Completed"否则结果="缺货交货"结束如果下一个End Sub我使用这个逻辑而不是
来打扰我的用户手动输入"OrderRemarks"的值。每当有特定订单缺少的项目时。因此,当系统发现订单在检查期间完美交付时,OrderRemarks将显示"交货已完成"。否则
"交付与缺乏"。这工作很好,但我想使用我的计算属性"OrderRemarks"的值。定义我的过滤器。恩。其中OrderRemarks =缺货交货此过滤器将用于显示交货期间缺货的所有订单。
不幸的是,计算属性不能用于定义查询。

解决方案

您不能将计算属性用作查询的一部分,因为计算在序列化和提交查询的数据库中实际不存在的属性。要解决此问题,您可以将计算的属性代码重构为可由RIA序列化的表达式
,并在计算属性和查询的PreprocessQuery方法中使用表达式。这样,您可以更改确定采购订单在一个地点是否不完整的代码。以下是我提出的建议:


PurchaseOrder实体代码:


 私有  Sub  OrderRemarks_Compute( ByRef 结果作为 字符串
如果 PurchaseOrder.IsDeliveryIncomplete( Me 那么
result = "缺货交付"
否则
result = "交货完成"
结束 如果
结束 Sub

公共 共享 ReadOnly 属性 IsDeliveryIncompleteExpression 作为表达式(Of Func(Of PurchaseOrder, Boolean ))
获取
'返回一个表达式,用于确定是否存在缺少大于0的详细项目
返回 功能 order As PurchaseOrder) order .PurchaseOrderDetails。任何功能(详细)detail.Lackings> 0)
结束 获取
结束 属性

私有 共享 ReadOnly 属性 IsDeliveryIncomplete As Func(Of PurchaseOrder,布尔
获取
返回 PurchaseOrder.IsDeliveryIncompleteExpression.Compile()
结束 获取
结束 物业


(TO THE LS TEAM) I find that there is no way we can define a query using a computed property of an entity. Here is the situation folks: I use a computed property to assign a value to my property "OrderRemarks" as follows Private Sub OrderRemarks_Compute(ByRef result As String) ' Set result to the desired field value for each d in me.PurchaseOrderDetail.Lackings if d.lackings <= 0 then result = "Delivery Completed" Else result = "Delivery with lackings" end if next End Sub I've resorted to this logic inorder not to bother my user to enter manually the value of "OrderRemarks" whenever there were items lacking in an specific orders. So when the system finds that an order was delivered perfectly during inspection OrderRemarks would display "Delivery Completed" otherwise "Delivery with Lackings". This work fine folks, but I wanted to use the value of my computed property "OrderRemarks" to define my filter. ex. Where OrderRemarks = Delivery with lackings This filter would be used to display all orders with lackings during delivery. Unfortunately, computed property can not be use in defining a query.

解决方案

You cannot use computed properties as a part of a query because computed properties to not actually exist in the database where the query will be serialized and submitted. To get around this problem, you can refactor your computed property code into an expression that is serializable by RIA and use the expression both in your computed property and in the PreprocessQuery method of the query. This way, you can change the code that determines if a purchase order is incomplete in one spot. Here's what I came up with:

Code for PurchaseOrder entity:

Private Sub OrderRemarks_Compute(ByRef result As String)
 If PurchaseOrder.IsDeliveryIncomplete(Me) Then
  result = "Delivery with lackings"
 Else
  result = "Delivery complete"
 End If
End Sub

Public Shared ReadOnly Property IsDeliveryIncompleteExpression As Expression(Of Func(Of PurchaseOrder, Boolean))
 Get
  ' Returns an expression that determins if there are detail items that have a lacking greater than 0
  Return Function(order As PurchaseOrder) order.PurchaseOrderDetails.Any(Function(detail) detail.Lackings > 0)
 End Get
End Property

Private Shared ReadOnly Property IsDeliveryIncomplete As Func(Of PurchaseOrder, Boolean)
 Get
  Return PurchaseOrder.IsDeliveryIncompleteExpression.Compile()
 End Get
End Property


这篇关于无法使用计算属性创建查询...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆