How to Extend MainProjectDataContext & use it in RCL project?

Hamed Vaziri 136 Reputation points
2023-07-10T16:30:38.5933333+00:00

Hi

I have a blazor server project as my main project with a configured dataContext called forexample : MainProjectDataContext.

Now i have a razor class library project which has a reference to my main blazor server project. in my rcl project i've added some classes as poco (without define any dataContext) to handle database transactions.

Now i have a some questions?

  1. How to extend my MainProjectDataContext in rcl project to handle database transactions for my new classes that i've created in my rcl project?
  2. how to add my new rcl dataContext to service providers & inject it into my razor files (with some options which i've configured in my main blazor server porject such as connectionString, ...)?

I will be grateful if you show with an example code.

Thanks in advance

Entity Framework Core
Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
678 questions
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,024 questions
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.
9,982 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Piyaphart Samutkang 0 Reputation points
    2023-07-10T18:19:53.6033333+00:00
    [type here]()
    
    0 comments No comments

  2. Bruce (SqlWork.com) 52,826 Reputation points
    2023-07-10T20:18:57.41+00:00

    .net does not allow circular references (two projects to ref each other). You should create third project for all shared code.

    0 comments No comments