XPO - Easy Way to Map a Property to a Read-Only Database Column (v18.2)

XPO Team Blog
25 July 2018

With v18.2, eXpress Persistent Objects™ (XPO) includes additional community-driven feature - FetchOnlyAttribute. Applied to a class property or field, this attribute indicates that you can only read values from a database. XPO will not include these values in INSERT and UPDATE SQL statements.

public class MyClass : XPLiteObject {
    // ...
    [FetchOnly]
    [Persistent("Total")]
    private double total;

    [PersistentAlias("total")]
    public double Total {
        get { return total; }
    }
}​

You can also set the Fetch Only option in the Data Model Designer. In the metadata, the XPMemberInfo.IsFetchOnly property returns True for such members.


Typical scenarios

This attribute is helpful when you need to map XPO class properties to:

  1. Computed database columns: when it is inefficient to implement them as read-only using PersistentAliasAttribute.
  2. Auto-increment database columns that are not primary keys (for example, rowversion).


How can I test this feature today?

Everyone can use our https://nuget.devexpress.com/early-access/api Nuget package source - it's free.  Check the Include prerelease option when finding and installing the package:


If you are an active DevExpress Universal subscriber and would like to test this feature prior to its official release, please email our support team at support@devexpress.com or rather create a separate private ticket in the Support Center. With that, we can verify your account and provide you with DevExpress Universal v18.2 Preview installer privately.

If you are using a trial and want to use this feature today without Nuget, you can also purchase a DevExpress Universal license online (this will give you access to early builds such as this CTP via installers). If you own a non-Universal subscription and are ready to upgrade, email us at clientservices@devexpress.com for preferential upgrade pricing.

Please report any issues and suggestions in the Support Center once you've had an opportunity to try this new feature in your upgraded v18.2 project. By providing early build access, we hope to find out whether our new features and solutions address your requirements and issues. Your testing efforts and your feedback help us deliver the best possible final implementation. We have described other benefits of this cooperation in this post.

Interesting Support Center tickets

  • We improved the consistency between the InMemoryDataStore and other SQL database providers (T648223);
  • AddXpoDefaultUnitOfWork and other XPO extension methods for ASP.NET Core DI are not available in XPO for the full .NET Framework. This API is for the .NET Core/Standard 2.0 version only (T657285); 
  • We bypassed and reported a Mono bug in which a Xamarin app consumed a WCF XPO-based service (T639333); 
  • We discussed dynamic type usage with our recent example: How to implement a OData4 service with XPO (T654401);
  • This was originally an XAF-related topic. Two long-time customers jumped in and shared their XPO related experience and performance best practices (T653665);
  • A reminder that PersistentAttribute, NonPersistentAttribute and PersistentAliasAttribute are exclusive. Only one can be applied to an XPO member. In addition, there is NO NEED to explicitly mark readonly (getter only) properties with NonPersistentAttribute. Members without a public setter are treated as non-persistent automatically (from a private ticket).

Find more interesting customer questions and product enhancements for your favorite products in the DevExpress Support Center (expand the "Frameworks (XAF & XPO)" group on the right) and What's New documentation (see resolved issues).


Your feedback is needed!

What do you think about this XPO feature and the new "Interesting Support Center tickets" rubric in particular? Please let our team know in the comments.


Love XPO and want to help us promote it? Add the package through Nuget.org instead of DevExpress Nuget!



  Yekaterina K.
  Technical writer
  XPO team

Free DevExpress Products - Get Your Copy Today

The following free DevExpress product offers remain available. Should you have any questions about the free offers below, please submit a ticket via the DevExpress Support Center at your convenience. We'll be happy to follow-up.
No Comments

Please login or register to post comments.