C
C#10mo ago
Ares

how can i fix this error?

hey so I have a asp.net core mvc app and for some reason suddenly it doesnt want to run anymore. it builds just fine but when i try to run it i get: MissingMethodException: Method not found: 'Microsoft.EntityFrameworkCore.Storage.CoreTypeMapping Microsoft.EntityFrameworkCore.Storage.TypeMappingSourceBase.FindMapping(System.Type, Microsoft.EntityFrameworkCore.Metadata.IModel)'. It says that it happens in my DbContext: 
using Microsoft.EntityFrameworkCore;

namespace realTimePolls.Models
{
public class RealTimePollsContext : DbContext
{
public RealTimePollsContext(DbContextOptions<RealTimePollsContext> options)
**: base(options) { }** <-- Error is here

public DbSet<Poll> Polls { get; set; }
public DbSet<User> User { get; set; }

public DbSet<UserPoll> UserPoll { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Poll>().ToTable("poll"); // Maps the Poll entity to the "poll" table
modelBuilder.Entity<User>().ToTable("user"); // Maps the User entity to the "user" table
modelBuilder.Entity<UserPoll>().ToTable("userpoll"); // Maps the User entity to the "user" table
}
}
}
using Microsoft.EntityFrameworkCore;

namespace realTimePolls.Models
{
public class RealTimePollsContext : DbContext
{
public RealTimePollsContext(DbContextOptions<RealTimePollsContext> options)
**: base(options) { }** <-- Error is here

public DbSet<Poll> Polls { get; set; }
public DbSet<User> User { get; set; }

public DbSet<UserPoll> UserPoll { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Poll>().ToTable("poll"); // Maps the Poll entity to the "poll" table
modelBuilder.Entity<User>().ToTable("user"); // Maps the User entity to the "user" table
modelBuilder.Entity<UserPoll>().ToTable("userpoll"); // Maps the User entity to the "user" table
}
}
}
I dont get why its not working, ive tried: Completely changing my project structure Deleting solution file and making a new one Cleaning solution Rebuilding Reinstalling all packages nothing seems to fix it. any advice? here is my repo: https://github.com/ForkEyeee/realtime-poll
No description
36 Replies
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Ares
AresOP10mo ago
thanks i didnt know about mysql being bad i used postgres when i was using js stack but i only switched to mysql cause my place of work uses it i think
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Ares
AresOP10mo ago
hm didnt know that i was actually gonna use postgres when i first started, but i switched to mysql last min. maybe when i finish i will change it to postgres
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Ares
AresOP10mo ago
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="8.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="8.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.1" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.0-beta.2" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="8.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="8.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.1" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.0-beta.2" />
</ItemGroup>
yeah this is the main csproj, i updated everything to 8. and then moved out all of the test dependencies to the test project. so i have the main projectr and the test project under the smae solution.
<ItemGroup>
<PackageReference Include="FakeItEasy" Version="8.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.1" />
<PackageReference Include="FluentAssertions" Version="7.0.0-alpha.3" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="xUnit" Version="2.6.6" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />

<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.10">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="FakeItEasy" Version="8.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.1" />
<PackageReference Include="FluentAssertions" Version="7.0.0-alpha.3" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="xUnit" Version="2.6.6" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />

<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.10">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
adn then this is the test csproj im able to run it now but there is one thing that i am having trouble with now which is detailed under this thread https://discord.com/channels/143867839282020352/1203036321757528147 i did my best to try to fix it for hours but i have had no luck
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX10mo ago
GitHub
GitHub - romantitov/MockQueryable: Mocking Entity Framework Core op...
Mocking Entity Framework Core operations such ToListAsync, FirstOrDefaultAsync etc - GitHub - romantitov/MockQueryable: Mocking Entity Framework Core operations such ToListAsync, FirstOrDefaultAsyn...
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Ares
AresOP10mo ago
my bad i made another thread because it seemed like a different issue. but some things: what do you mean by split test and their dependencies?, as far as i know, i should have the testing dependencies in in the test project, and then everything else in the main project right? am i misunderstanding something here? also the thing is, ive had the tests run before and they pass with all green. i can also run it in the cli and they pass. but as far as testing, creating an in memory database is not a good practice? i should use the actual database instead? I think i shuold switch to postgres now but im not sure about the above.
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Ares
AresOP10mo ago
yes i did, i moved them so they are not all in the same csproj. i dont know why i testing stuff in the main csproj but its not like that anymore
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Ares
AresOP10mo ago
do you mean <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.10"> ? yes i dont think this should be in the testing csproj
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Ares
AresOP10mo ago
oh
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Ares
AresOP10mo ago
to be honest ive never used docker before i know its so that it can containorize yoru app so it can run anywhere but no mor ethan that. its on my to learn though
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Ares
AresOP10mo ago
ok, so i should be testing like this then, i didnt know. cause i watched a video on unit testing and it didnt mention any of the above
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Ares
AresOP10mo ago
oh man thisis alot of information lol. i only started learning .net a week ago, i come from a js background. but i think the firs tthing i should do is switch to postgres right? then i can look into fixing my testing process?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Ares
AresOP10mo ago
i still dont undertand where docket comes into play here but i can look at that while im doing this right?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Ares
AresOP10mo ago
okay i always thought of e2e like testing in a browser like th euser can clicka buutton adn then something happens didnt know it can be with just code too
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Ares
AresOP10mo ago
ok ill have to check it out then. i dont know why i was using just xunit, i didnt want to run just unit tests, i just wanted to run any sort of tests to be honest. with some googling i was led to xunit and just started using that exclusively.
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Ares
AresOP10mo ago
oh yeah okay, this is alot of new info lol so i think i will start by switchinig to postgres, and then i will follow the integration test tutorial and try to make sure my dpeendndcies are in order while doing all of that
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Ares
AresOP10mo ago
really? i thought that was the way to do it, atleast according to the msdocs i think
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Ares
AresOP10mo ago
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;

private readonly RealTimePollsContext _context; // Declare the DbContext variable

public HomeController(ILogger<HomeController> logger, RealTimePollsContext context) // Inject DbContext in the constructor <-----------
{
_logger = logger;
_context = context; // Initialize the _context variable. This is my DbContext instance.
}

public IActionResult Index()
{
var polls = _context.Polls.ToList();
var pollTitles = polls.ConvertAll<string>(poll => poll.Title);
var viewModel = new PollsViewModel { Polls = polls, PollTitles = pollTitles, };
return View(viewModel);
}
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;

private readonly RealTimePollsContext _context; // Declare the DbContext variable

public HomeController(ILogger<HomeController> logger, RealTimePollsContext context) // Inject DbContext in the constructor <-----------
{
_logger = logger;
_context = context; // Initialize the _context variable. This is my DbContext instance.
}

public IActionResult Index()
{
var polls = _context.Polls.ToList();
var pollTitles = polls.ConvertAll<string>(poll => poll.Title);
var viewModel = new PollsViewModel { Polls = polls, PollTitles = pollTitles, };
return View(viewModel);
}
so something like this is not recommended? how woudld you do it instead?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Ares
AresOP10mo ago
thank you
Want results from more Discord servers?
Add your server