GithubHelp home page GithubHelp logo

devexpress-examples / xaf_generate-a-sequential-number-for-a-persistent-object-within-a-database-transaction Goto Github PK

View Code? Open in Web Editor NEW
9.0 58.0 5.0 434 KB

How to generate a sequential number for a persistent object within a database transaction in eXpressApp Framework

License: Other

C# 78.11% HTML 21.89%
dotnet xaf framework ef-core expressapp expressapp-framework expressappframework xpo

xaf_generate-a-sequential-number-for-a-persistent-object-within-a-database-transaction's Introduction

XAF - How to generate a sequential number for a persistent object within a database transaction with Entity Framework Core

This example illustrates how to implement a business object with an identifier field with autogenerated sequential values.

image

This Readme focuses on Entity Framework Core. For information on how to achieve the same functionality with XPO, see the Readme.md file in the XPO solution's folder.

Implementation Details

Entity Framework Core allows you to set up generation of sequential values for non-key data fields as described in the following article in the Entity Framework Core documentation: Generated Values - Explicitly configuring value generation.

Use the steps below to generate sequential values for a business object's property so that the property is assigned a value once the object has been saved to the database:

  1. Add the [DatabaseGenerated(DatabaseGeneratedOption.Identity)] attribute to the required business object property:

    public class Address : BaseObject {
        // ...
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public virtual long SequentialNumber { get; set; }
        // ...
    }
  2. Add the following code to the DbContext's OnModelCreating method implementation so that the generated values are always displayed in the UI immediately after the object has been saved:

    public class GenerateUserFriendlyIdEFCoreDbContext : DbContext {
        // ...
        protected override void OnModelCreating(ModelBuilder modelBuilder) {
            // ...
            modelBuilder.Entity<Address>().UsePropertyAccessMode(PropertyAccessMode.FieldDuringConstruction);
        }
    }

As an alternative technique, you can use a database-specific sequence object to generate sequential values as described in the following article: Sequences.

Files to Review

Documentation

xaf_generate-a-sequential-number-for-a-persistent-object-within-a-database-transaction's People

Contributors

anastasiakiseleva avatar andreykozhevnikov avatar devexpressexamplebot avatar dxmi avatar eugeniyburmistrov avatar maksimkarpenko avatar nikolaevairina avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.