Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Project structure with C# and EfCore

Project structure with C# and EfCore

Scheduled Pinned Locked Moved C#
csharptutorialasp-netvisual-studiosysadmin
5 Posts 4 Posters 10 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nwbkn
    wrote on last edited by
    #1

    Hi, I'm currently learning how to use Entity Framework Core and I'm trying to create a "more advanced" application divided into multiple projects. When I was using ADO.NET, I would usually make: - Project.DatabaseAccess - for managing connection strings, - Project.Shared - base classes and interfaces (which implement INotifyPropertyChanged) - for example Project.Customers - models for customer-related stuff and a static class with CRUD methods for them. Customers would then reference the Shared and DatabaseAccess projects. When using EfCore, I wanted to achieve similar structure, so: - Project.DatabaseAccess - managing connection strings, main DbContext - Project.Shared, - Project.Customers - models for customer-related stuff and repositories for them (with DbContext provided in the constructor) The problem with that approach is that Customers reference to the DatabaseAccess (for accessing DbContext), and DatabaseAccess needs to reference to the Customers (because it has DbSet). Unfortunately, you can't make A<-->B references in the Visual Studio. What other project structures do you recommend? I know that there is something called CleanArchitecture (Application, Domain, Infrastructure), but it doesn't provide the separation between different spheres of my program (Project.Customers, Project.Planning, Project.Mailing, etc.) Thank you in advance!

    J 1 Reply Last reply
    0
    • N nwbkn

      Hi, I'm currently learning how to use Entity Framework Core and I'm trying to create a "more advanced" application divided into multiple projects. When I was using ADO.NET, I would usually make: - Project.DatabaseAccess - for managing connection strings, - Project.Shared - base classes and interfaces (which implement INotifyPropertyChanged) - for example Project.Customers - models for customer-related stuff and a static class with CRUD methods for them. Customers would then reference the Shared and DatabaseAccess projects. When using EfCore, I wanted to achieve similar structure, so: - Project.DatabaseAccess - managing connection strings, main DbContext - Project.Shared, - Project.Customers - models for customer-related stuff and repositories for them (with DbContext provided in the constructor) The problem with that approach is that Customers reference to the DatabaseAccess (for accessing DbContext), and DatabaseAccess needs to reference to the Customers (because it has DbSet). Unfortunately, you can't make A<-->B references in the Visual Studio. What other project structures do you recommend? I know that there is something called CleanArchitecture (Application, Domain, Infrastructure), but it doesn't provide the separation between different spheres of my program (Project.Customers, Project.Planning, Project.Mailing, etc.) Thank you in advance!

      J Offline
      J Offline
      jschell
      wrote on last edited by
      #2

      nwbkn wrote:

      you can't make A<-->B references in the Visual Studio

      You can use interfaces for circular references.

      nwbkn wrote:

      Customers reference to the DatabaseAccess

      Your Data API layer accepts DTOs (Data Transfer Object) and returns DTOs. So 'Customer' is a DTO which the CustomerDB class uses. Although you can choose your own names for the classes. Create Data Transfer Objects (DTOs) | Microsoft Learn[^] Be very careful about what you put in a DTO. Probably to start out you should have nothing but properties.

      N Richard Andrew x64R 2 Replies Last reply
      0
      • J jschell

        nwbkn wrote:

        you can't make A<-->B references in the Visual Studio

        You can use interfaces for circular references.

        nwbkn wrote:

        Customers reference to the DatabaseAccess

        Your Data API layer accepts DTOs (Data Transfer Object) and returns DTOs. So 'Customer' is a DTO which the CustomerDB class uses. Although you can choose your own names for the classes. Create Data Transfer Objects (DTOs) | Microsoft Learn[^] Be very careful about what you put in a DTO. Probably to start out you should have nothing but properties.

        N Offline
        N Offline
        nwbkn
        wrote on last edited by
        #3

        Thanks for the response!

        1 Reply Last reply
        0
        • J jschell

          nwbkn wrote:

          you can't make A<-->B references in the Visual Studio

          You can use interfaces for circular references.

          nwbkn wrote:

          Customers reference to the DatabaseAccess

          Your Data API layer accepts DTOs (Data Transfer Object) and returns DTOs. So 'Customer' is a DTO which the CustomerDB class uses. Although you can choose your own names for the classes. Create Data Transfer Objects (DTOs) | Microsoft Learn[^] Be very careful about what you put in a DTO. Probably to start out you should have nothing but properties.

          Richard Andrew x64R Offline
          Richard Andrew x64R Offline
          Richard Andrew x64
          wrote on last edited by
          #4

          jschell wrote:

          You can use interfaces for circular references.

          I learn something new every time I visit this website!

          The difficult we do right away... ...the impossible takes slightly longer.

          W 1 Reply Last reply
          0
          • Richard Andrew x64R Richard Andrew x64

            jschell wrote:

            You can use interfaces for circular references.

            I learn something new every time I visit this website!

            The difficult we do right away... ...the impossible takes slightly longer.

            W Offline
            W Offline
            Waqas Khan 2024
            wrote on last edited by
            #5

            difficulties gives us new challenges and something new to learn.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups