Search code examples
c#blazorblazor-client-side

Blazor wasm, net core hosted, with authentication, relationships between applicationuser and my models in the shared project


I'm studying Net Core and Blazor and I'm facing the following problem.

I created a new Blazor web assembly solution, net core hosted with user authentication. The solution is split in three projects by default: client, server and shared. I put my models in the shared project but now I need to set relationships (one-to-many, many-to-many, ... as described here: https://learn.microsoft.com/en-us/ef/core/modeling/relationships ) between my models and the ApplicationUser model which lives inside the server project.

Inside my model I can't put

public ApplicationUser User { get; set; }

because I cannot do this

using mysolutionname.server;

because the server project depends on shared and shared cannot depend on server (circular dependency).

How do I solve this?


Solution

  • The Shared project should contain only objects that are shared by the Client and the Server projects. As for instance, the WeatherForecast class, used by the Client and Server projects in the default Visual Studio Template, resides in the Shared project, as both projects make use of this class. But objects such as the ApplicationUser (or ApplicationDbContext) are only used on the server, must not and cannot be used on the Client project, and their current location as produced by the default template should not be changed in the way you thought.

    Hope this helps...