Computed properties in queries

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
Dredding
Posts: 3
Joined: Fri 15 Sep 2017 14:33

Computed properties in queries

Post by Dredding » Fri 15 Sep 2017 14:38

Good morning;

Is it possible to mark a property in an entity as computed? What i'm attempting to do is compose a query with expression trees and I need to query my DB based on the expression within a property; Preferably by way of writing the final SQL to represent the property (IE: [psudo](Where x & 1) >0)

Pinturiccio
Devart Team
Posts: 2420
Joined: Wed 02 Nov 2011 09:44

Re: Computed properties in queries

Post by Pinturiccio » Wed 20 Sep 2017 13:26

There is no such possibility.

Dredding
Posts: 3
Joined: Fri 15 Sep 2017 14:33

Re: Computed properties in queries

Post by Dredding » Tue 26 Sep 2017 20:34

Fortunately, I created a way to do it.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Computed properties in queries

Post by Shalex » Wed 27 Sep 2017 15:33

As a workaround, compute a column value at the database side (e.g.: via a trigger) and set Auto Generated Value=True, Auto-Sync=OnInsert for the corresponding property in the model.

Dredding
Posts: 3
Joined: Fri 15 Sep 2017 14:33

Re: Computed properties in queries

Post by Dredding » Mon 02 Oct 2017 19:27

Thank you.

I found a fairly robust way to accomplish the same goal is to inherit from the base entity and using auto-mapper, map individual "Calculated" fields while selecting the inherited DTO.

This accomplishes my goal of having the calculated fields aliased in the query so they can be accessible to down-stream predicates. Additionally, I don't have to change the schema; although I agree that would be the simplest solution.

Post Reply