Using Two Entity-Framework Approaches in One .Net Solution To Access One Database

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
6 years ago
Hi friends I'm new here. I'm using NopCommerce (version 3.90) as a solution to a fashion based eCommerce web application to provide to my client after modifying it as per his requirements.

NopCommerce uses Entity Framework's Code-First approach. In NopCommerce, creating a new entity or modifying some existing entity requires many changes in many places. I'm also not fully aware of all
processes happening in NopCommerce's code right now so I'm avoiding to touch the existing code as far as I can. But as I already said, I have to modify it as per client's requirements and to do it, I want to use DB-First approach in the same solution where Code-First is already being used as I'm more comfortable with DB-First.

Thats why I want to ask that is it fine to use 2 approaches which are Code-First (already being used) and DB-First (I want to use) in the same .net solution ?

is it prone to errors in future for an e-commerce site and if so, what are those possible errors ?

what is the right way to use these 2 entity-framework approaches simultaneously in the same .net solution ?

please note that both of these approaches will be using one single Nop database.

Thanks & Regards,
Sumit
6 years ago
Using two different approaches in same solution doesn't looks a great idea. It would end up creating issues with code and project structure.

1. If DB first approach is used, it can override models you already have in solution (if you are using Models as View Models, which sometimes we do if we are developing a small plugin).

2. Verifying and testing existing functionality will be a time consuming task. As a thumb rule, new changes should not lead to a situation where existing functionality is broken.

3. Re-applying validations, if not using Fluent API.

Better option is to continue with code-first approach, not many changes are required. You can refer this article.
http://docs.nopcommerce.com/pages/viewpage.action?pageId=1442499
6 years ago
Thank you Rahul for your advice. I will use the existing Code-First approach and retain the code structure as it is. It may take some time understanding Nop's way of creating new entities and modifying the existing entities but it will help a lot by eliminating future issues.

Thanks & Regards,
Sumit
6 years ago
Hi Rahul,

The link you sent covers how to add a property to the "Category" entity. Is there a link to create a new entity in NopCommerce code and do the required database mappings ?

Thanks,
Sumit
6 years ago
[email protected] wrote:
Hi Rahul,

The link you sent covers how to add a property to the "Category" entity. Is there a link to create a new entity in NopCommerce code and do the required database mappings ?

Thanks,
Sumit


You have to follow same procedure and add new entities, and new properties. Yes, database mappings are required if some new table is created or existing table is modified. If using property only for the business logic and it is not  related to any table, use [NotMapped] annotation.
6 years ago
Thanks a lot.

Regards,
Sumit
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.