Blazor w/ Entity Framework Core - compile error

blazor entity-framework-core


I have the following setup but am unable to finish building as I get an obscure error related to line 439 in file Blazor.MonoRuntime.targets (MSB3073).

Does this essentially mean that Entity Framework Core will in no way work with Blazor preview 6?


  • Hosted Blazor
  • AspNetCore.Blazor (3.0.0-preview6.19307.2)
  • Microsoft.EntityFrameworkCore (3.0.0-preview6.19304.10)
  • Microsoft.EntityFrameworkCore.Design (3.0.0-preview6.19304.10)
  • Microsoft.EntityFrameworkCore.SqlServer (3.0.0-preview6.19304.10)

Resolved via a hack solution!

Somehow I was able to resolve everything and makes things run end-to-end. I believe the big, critical thing was:
* Ensure that the Blazor client AND server projects do not directly reference Entity Framework
* Do not let the Blazor client reference (directly or indirectly) the project with the generated entities). To get access to the models, I just create a duplicate of the generated entities (and removed the "partial" from the classes that were generated)

7/2/2019 4:28:12 PM

Accepted Answer

Some clarification is needed here, right:

  • You cannot use Entity Framework on the Client project of Blazor. Entity Framework is a server technology.

  • You may use Entity Framework on the Server project of your application.

  • Communication between your Client side and Server hosting side is ordinarily done via Http calls (HttpClient service), but you may also employ SignleR.

  • To enable Http calls you should expose Http routing endpoints... This can be enabled by using Web Api with the required endpoints. Your Web Api exposed methods (Controllers' methods) can access the database directly (or indirectly if you define repositories, services, etc) via Entity Framework objects, and return the queried data to the calling methods (HttpClient methods).

Note that in my answer I particularly relate to Blazor Client-side apps, but it is mostly true with regards to Blazor server-side apps. I may just add here that in Blazor server-side apps you don't have to use Web Api since Blazor is executed on the server. In such a case, you can define a normal service to retrieve the data from the database, and pass it to the calling methods (no HttpClient involved here).

  • The Shared project intended to contain objects that can be used by both the front end and back end. This is the place where you can define your Model objects. As for instance, you can define an Employee class that can be used to retrieve the data and pass it to the Client as a list of Employee objects, and in the Client you can define a list of Employee objects that will store the retrieved data. In short, you don't have to define two types of objects, one appropriate to the server, and one appropriate to the client (say your client is an Angular app).

Hope this helps..

7/2/2019 5:47:40 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow