Can I Use Entity Framework for Plugin Development?

2 months ago
Hello nopCommerce community,

I have been developing a plugin using nopCommerce for quite some time, and during this period, I have been using the FluentMigrator library to handle database operations. However, some limitations I encountered and the constant need to manually add and delete data during my developments made me think.

Therefore, I have some concerns about using Entity Framework in my developments. I would like to learn about your experiences and recommendations regarding this.

    Possible Conflicts: Could there be any conflicts if I use Entity Framework instead of FluentMigrator? Can both libraries be used together?

    Performance Impact: How does Entity Framework compare to FluentMigrator in terms of performance? Are there potential performance issues with larger databases?

    Community Experience: Have others used Entity Framework for nopCommerce plugin development? What are your experiences?

    Recommendations and Caveats: If I decide to use Entity Framework, what are the critical points to be aware of? Any recommendations?

I would greatly appreciate it if you could share your knowledge and opinions on this matter. Thank you!
2 months ago
mk148a wrote:
...using the FluentMigrator library to handle database operations. However, some limitations I encountered and the constant need to manually add and delete data during my developments made me think...


What "database operations" are you referring to?
FluentMigrator is a database migration framework used to manage versions of database changes in code.


RE: "constant need to manually add and delete data"
As part of "installation" (& upgrade), or for access to data during regular run time?


RE: "some limitations"
FYI: With Linq2DB, you can execute raw SQL if you need to. Example:
\Libraries\Nop.Data\DataProviders\MySqlDataProvider.cs
var tables = currentConnection.Query<string>($"SHOW TABLES FROM `{currentConnection.Connection.Database}`").ToList();
...
await currentConnection.ExecuteAsync($"OPTIMIZE TABLE `{string.Join("`, `", tables)}`");

2 months ago
Oh sorry, I never answered your actual question ;)

While it’s technically possible to use Entity Framework in a plugin, I would think that it’s generally not recommended if the core system is using Linq2DB. Here are a few reasons:

Consistency: Using the same ORM (Object-Relational Mapping) across the entire application ensures consistency and can make the code easier to understand and maintain.

Performance: Linq2DB is more performant.

Compatibility:  Maybe you will only be using your new plugin on one site with a specific DB.  But otherwise, EF may have issues supporting the other DBs that nopC supports, e.g. MySql, PostgreSQL, any future additions.

Memory: You'll need to include the EF libraries in your plugin.