How to prevent tight coupling when using EF models in ViewModels and Services (WPF MVVM)

fatih uyanık 225 Reputation points
2025-04-17T06:48:43.8433333+00:00

Hello,

In a WPF MVVM application, I'm using a layered architecture:

  • Data Layer: EF Core models (e.g., Book, Member)
  • Business Layer: Service classes
  • Presentation Layer: WPF ViewModels

Currently, I use EF entity classes directly in my service methods and ViewModel properties.

Example:

public class BookService
{
    public Book GetById(int id); // using EF entity
}
public class BookViewModel
{
    public Book SelectedBook { get; set; } // also EF entity
}

I want to avoid tight coupling between layers.

✅ What is the best way to replace EF entities in the ViewModel layer without breaking the architecture?

• Should I use DTOs in the service layer and map them manually or with a tool like AutoMapper?

• Is there a recommended lightweight method to map between EF entities and DTOs for simple CRUD apps?

Thanks in advance.

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,462 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.