© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
125 replies
Tim

Issue with DbContext reading in DB Tables

I am trying to use DbContext and the optionsBuilder to connect to my database and obtain a table called "Card". I am doing the following command in
OnConfiguring
OnConfiguring
:
optionsBuilder.UseSqlite($"Data Source=mtg.db");
optionsBuilder.UseSqlite($"Data Source=mtg.db");


and also have the following object instantiated in the same class:

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


Then, in my main method I run the following lines:

            var context = new MtgContext();
            var dbCards = context.Card.ToList();
            Console.WriteLine(dbCards);
            var context = new MtgContext();
            var dbCards = context.Card.ToList();
            Console.WriteLine(dbCards);

I get an error that "Card" is not a known table even though I have a Card table in the database. What am I doing wrong?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

BackgroundService and dbcontext memory issue
C#CC# / help
2y ago
❔ DbContext
C#CC# / help
4y ago
❔ ✅ Issue with data reading from database
C#CC# / help
3y ago
✅ Disposing dbContext with dependency injection
C#CC# / help
14mo ago
Next page