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)
-
0
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.
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0
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
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0
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
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0
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
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0
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
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)