Open Closed

Existing Database #2846


User avatar
0
sraptis created

Dear all,

as a company, we have developed an application that uses an MSSQL database. This is the application we want to port using abp framework. Our question is: It is possible to use the current database keeping also the existing data? Mean to keep the schema with the same primary keys? (adding more columns needed by saas is not an issue) The primary key for each table is of the form [TableName][ID] e.g.: for the table Invoice the primary key is InvoiceID of type Integer

Thank you in advance,

Stavros Raptis on behalf of I2QS


9 Answer(s)
  • User Avatar
    0
    Radoslav created

    Assuming you have this existing table: CREATE TABLE AbpOrganizations ( OrganizationID int IDENTITY(1,1) PRIMARY KEY, Name varchar(255) NOT NULL );

    You need to understand these settings: // Configures a property to never have a value generated when an instance of this // entity type is saved. // Note that temporary values may still be generated for use internally before a // new entity is saved. public new virtual PropertyBuilder<TProperty> ValueGeneratedNever()

    // Configures a property to have a value generated only when saving a new entity, // unless a non-null, non-temporary value has been set, in which case the set value // will be saved instead. The value may be generated by a client-side value generator // or may be generated by the database as part of saving the entity. public new virtual PropertyBuilder<TProperty> ValueGeneratedOnAdd()

    builder.Entity<Organization>(b => { b.ToTable(EventHubConsts.DbTablePrefix + "Organizations", EventHubConsts.DbSchema); b.ConfigureByConvention(); b.Property(x => x.Id).HasColumnName("OrganizationID").ValueGeneratedNever();

    public class Organization : Entity<int> { public string Name { get; private set; } }

    You need to make your model always in sync with DB. I think you cannot do code migrations, unless extra work is done to synchronize model with DB.

  • User Avatar
    0
    sraptis created

    Hi again,

    do you have any source code examples on GitHub? Any template? At the moment the existing database has more than 300 tables and applying this workaround to each table and testing it will take an eon. And it is not only the change of the primary key. The saas adds its own columns that in your scenario should be added manually. If you have a complete whitepaper of porting to ABP framework an existing database schema it will be more than welcome.

    Best regards,

    Stavros Raptis

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    https://docs.abp.io/en/commercial/latest/abp-suite/generating-entities-from-an-existing-database-table

  • User Avatar
    0
    Radoslav created

    Hi again,

    do you have any source code examples on GitHub? Any template? At the moment the existing database has more than 300 tables and applying this workaround to each table and testing it will take an eon. And it is not only the change of the primary key. The saas adds its own columns that in your scenario should be added manually. If you have a complete whitepaper of porting to ABP framework an existing database schema it will be more than welcome.

    Best regards,

    Stavros Raptis

    This is involved. @mailming mentioned you could buy abp commercial version. There is a way to do it without it and to find a way for migration to continue to handle further develpment. You can contact me at radvistaATgmailDOTnet

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    @sraptis has the commercial license.

  • User Avatar
    0
    tsarris@i2qs.com created

    Can we have an official answer from the Support Team, please? Is there a way to keep existing tables with data, and keeping existing primary keys in the form the my cooperator refers? Is there any instructions how will do it? Is there any example of this functionality?

    Thank you Tasos Sarris on behalf of I2QS

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You can use tools to generate classes from database. Then convert this class to abp entity or aggregate. Then configure these entities in ef module.

    https://www.entityframeworktutorial.net/efcore/create-model-for-existing-database-in-ef-core.aspx

  • User Avatar
    0
    Radoslav created

    This will not enable EF migration to take control of future changes. This will enable you use EF with abp.io.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    You also need to convert these classes to ABP entity or aggregate. Then configure these entities in the EF module.

Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11