Answered by:
MVVM model witout using the EntityFrameWork (Razor)

Question
-
User-1063667917 posted
Hi,
I'm a rookie at Net Core using Razor pages and I have doubts about how to use the MVVM model but witout using the EntityFrameWork (which I consider it useful just on basic things)
So I'm doing this, please let me know if I'm wrong on best practices:
Model - It's a pure class file with only properties inside the Models directory
View - HTML and C# code behindSo far, so good, but where should I put the database and logical layers? (like LoadClients using LoadDatatable)
I created a directory "Classes" and there I have Clients.cs and Database.cs.
am I doing something wrong with this?
Maybe functions in Clients.cs should be inside the Model...
Thanks in advance.
Tuesday, March 2, 2021 9:19 PM
Answers
-
User-474980206 posted
I'd put them in a separate project(s). The razor project should just have the UI code and only the UI code.
there should be a database layer project and a business (logic) layer project. The UI project should only reference the business layer, and its classes should be injected.
the database layer should implement interfaces used by the logic layer. then you can mock, and write unit tests for the business layer.
note: EF just implements a DB repository. You are free to build your own, as I use database first, I seldom use EF.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, March 2, 2021 9:59 PM -
User1120430333 posted
You only have a part of it MVVM which is SoD.
Understanding Basics of UI Design Pattern MVC, MVP and MVVM - CodeProject
Then there is a bigger design pattern the MVVM can be implemented in that is using SoC
Separation of concerns - Wikipedia
You might want to look into Layered style.
Chapter 3: Architectural Patterns and Styles | Microsoft Docs
You can look into writing clean code.
ASP.NET - Writing Clean Code in ASP.NET Core with Dependency Injection | Microsoft Docs
Architectural principles | Microsoft Docs
New is Glue | Blog (ardalis.com)
I like to use the DAO pattern in the DAL
Data Access Object (DAO) design pattern in Java - Tutorial Example (javarevisited.blogspot.com)
And about using EF on basic things don't kid yourself now. :)
I have used EF DB first behind an ASP.NET WCF Web service that was doing CRUD operations for an over 80 objects Model with the DAO pattern in the DAL. EF is far more or any ORM like nHibernare are way far more that a basic usage.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, March 2, 2021 10:54 PM
All replies
-
User-474980206 posted
I'd put them in a separate project(s). The razor project should just have the UI code and only the UI code.
there should be a database layer project and a business (logic) layer project. The UI project should only reference the business layer, and its classes should be injected.
the database layer should implement interfaces used by the logic layer. then you can mock, and write unit tests for the business layer.
note: EF just implements a DB repository. You are free to build your own, as I use database first, I seldom use EF.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, March 2, 2021 9:59 PM -
User1120430333 posted
You only have a part of it MVVM which is SoD.
Understanding Basics of UI Design Pattern MVC, MVP and MVVM - CodeProject
Then there is a bigger design pattern the MVVM can be implemented in that is using SoC
Separation of concerns - Wikipedia
You might want to look into Layered style.
Chapter 3: Architectural Patterns and Styles | Microsoft Docs
You can look into writing clean code.
ASP.NET - Writing Clean Code in ASP.NET Core with Dependency Injection | Microsoft Docs
Architectural principles | Microsoft Docs
New is Glue | Blog (ardalis.com)
I like to use the DAO pattern in the DAL
Data Access Object (DAO) design pattern in Java - Tutorial Example (javarevisited.blogspot.com)
And about using EF on basic things don't kid yourself now. :)
I have used EF DB first behind an ASP.NET WCF Web service that was doing CRUD operations for an over 80 objects Model with the DAO pattern in the DAL. EF is far more or any ORM like nHibernare are way far more that a basic usage.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, March 2, 2021 10:54 PM -
User-1063667917 posted
Thanks Bruce, this helped me a lot.
Wednesday, March 3, 2021 5:31 AM -
User-1063667917 posted
Thanks for the references DA, they will light my path.
Wednesday, March 3, 2021 5:32 AM