It seems that you create and implement new netstandard2.0
class library (or service) that reference another service project built on .net framework v4.7.2
, and now you'd like to perform EF database operations by consuming new methods in netstandard2.0
project from Blazor Server app.
You can try to install EntityFramework
in Blazor Server app, then build and run the project to check if it can work as expected.
<PackageReference Include="EntityFramework" Version="6.4.4" />
Testing code below work well on my side, you can refer to it and compare with your projects.
Call method in netstandard2.0
project from Blazor server app
var ts = new MyStu();
var success = ts.create();
if (success)
{
//code logic here
Method in netstandard2.0
project
public class MyStu
{
public bool create()
{
var ts = new TestService();
return ts.CreateStudent();
}
Method CreateStudent
in .net framework v4.7.2
project
public bool CreateStudent()
{
SchoolDbContext db = new SchoolDbContext("connection_string_here");
db.Students.Add(new Student
{
FirstMidName = "F",
LastName = "L"
});
db.SaveChanges();
return true;
}
Test Result
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
With Regards,
Fei Han