This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I am trying to created a calculated field in an entity in such a way as it can be used in a query expression. I have added the code below to a partial class.
/// <summary>Returns the difference between the amount issued and the amount returned.</summary> Then in my Query I have a clause. qry.QueryExpression = Entity.Attribute(StockMovement.QtyBalance) >= 1; But when I execute the Find<T>(qry); I receive an error that. Could not find field [QtyBalance] on model [StockMovement] Am i missing something? Stupid question, of course I am missing something, I just don;t know what. Thanks
|
|
|
This isn't possible as written. The QtyBalance property getter is compiled and opaque to us -- we can't decode that compiled representation in order to turn it into query expressions. (This problem isn't unique to LightSpeed: for example, you'll have the same thing in LINQ to SQL.) So you will need two representations, a CLR representation for the property implementation and an expression representation for querying: public decimal QtyBalance { get { return /* ... */; } } public static readonly QueryExpression QtyBalanceExpression = Then in your query you would have to use the expression version: Find<StockMovement>(QtyBalanceExpression >= 1); (I have not tested these exact expressions but this should give you an idea.) There is a trick you can use in LINQ to avoid the duplication of logic but you still end up with two "things", an executable CLR property and a descriptive expression. Let me know if you need more info about this. |
|
|
Hi Ivan, thanks for the reply. I regret to inform you that your suggested code did not work, as you said it might not. The basic problem is in the Find<StockMovement>(QtyBalanceExpression >= 1); The reason it failed is that QtyBalanceExpression is a QueryExpression and hence cannot be compared to a number. However, I did find a way around it using your ideas above. So thanks again for helping me out. Regards |
|