We just purchased ASP.NET Zero to rewrite an internal application. Your documentation is great, and we've been able to add some simple pages in no time at all!
However, all our data already exists in SQL Server, and is touched by multiple teams, so we can't really use Code First, and I have not seen any documentation on what the best practices are for accessing that in the ASP.NET Zero world. Can you help?
Thanks, Dave
8 Answer(s)
-
0
Hi,
AspNet Zero (and ABP framework) designed to work with Code-First approach and for new applications. Existing databases and Db-first are not considered much.
For your case, I suggest to create EF Code-First classes for your existing database. Entity Framework & Visual Studio can automatically make it. After creating models, you can adapt models to ABP infrastructure (Derive entities from Entity class, derive your DbContext from AbpZeroDbContext and so on). Thus, you can use your existing database within AspNet Zero project. But, if I was in such a situation, I don't think to create all database entities in once. I start to create a few entities and just create needed entities while I developing pages. So, all entities are created by the time.
-
0
+1 for the suggested approach.
We used to have same Scenario, and we end up creating code-first like classes and entities by adapting then as we go...
Regards
Bruno Bertechini
-
0
When I tried this, though, ABP wants to automatically add the "Id" field to my existing table, and then it wants to run the database migrations, which I don't want to do...
Dave
-
0
Hi,
- You can override Id property for your entity then add [Column("YourId")] attribute to the Id property.
- No problem, just generate migration, then empty the Up and Down methods (delete codes in the methods) and update-database. Also, if you want, you can completely remove code-first migration system.
-
0
Thank you for your response. I really appreciate it because there are things I'm not understanding.
I have done this:
public class DealerKioskSetting : Entity { [Column("DealerKioskId")] public override int Id { get; set; } //[Key] //public int DealerKioskId { get; set; }
and when I do that, I get the following in my JSON data (from the console):
..."dealerKioskId":0, "id":1234...
So, my question now is... why is dealerKioskId showing up there at all? The id value is the correct dealerKioskId in this example.
Thank you, Dave
-
0
Or, are you saying I should override Id and keep DealerKioskId as well?
-
0
Should I also remove DealerKioskId from my DealerKioskSettingsListDto ? Do I need to override Id there or do anything, or will it just be handled correctly at that point?
Thanks, Dave
-
0
Hi,
No need to DealerKioskId in entity and dto anymore. just remove all. We suggest to name id as Id for all entities rather than entity specific Id naming (like DealerKioskId).
Thanks.