question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TableAttribute doesn't work, but .ToTable() works

See original GitHub issue

Note: I am using MySQL & its sample database ‘World’

Project.json

"frameworks": {
    "netstandard1.6": {
      "dependencies": {
        "NETStandard.Library": "1.6.1",
        "MySQL.Data.EntityFrameworkCore":"7.0.6-ir31"
      }
     }
  }

Model:

using System.ComponentModel.DataAnnotations.Schema;
[Table("Country")]   // This is actual table name in database
    public class Countries
    {
        [Key]
        public string Code { get; set; }
        public string Name { get; set; }
        public string Continent { get; set; }
        public string Region { get; set; }
        public int IndepYear { get; set; }
    }

DbContext:

public class WorldContext : DbContext
 { 
         DbSet<Countries> Countries {get;set;}

        protected override void OnConfiguring(DbContextOptionsBuilder optionBuilder)
        {            optionBuilder.UseMySQL("server=localhost;userid=root;pwd=Newuser123;port=3306;database=world;sslmode=none;");
        }
}

When I write code to fill & fetch Countries using linq, I am getting error like ‘Countries’ table does not exist.

However, when I comment the [Table("Country")] from model class, and add following code under context class, it works:

protected override void OnModelCreating(ModelBuilder modelBuilder)
 {
       modelBuilder.Entity<Countries>()
           .ToTable("Country");
 }

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ajcvickerscommented, Jan 5, 2017

@avikenjale Sorry, I misread your message. Diego pointed you to the correct MySQL contact.

1reaction
divegacommented, Jan 5, 2017

cc @gmartinezsan from the MySQL team as FYI.

Read more comments on GitHub >

github_iconTop Results From Across the Web

84423: .net core - TableAttribute doesn't work, but .ToTable ...
However, when I comment the [Table("Country")] from model class, and add following code under context class, it works: protected override void ...
Read more >
EntityTypeBuilder does not contain a definition for ToTable ...
I was testing out some example from MS website, but I can't find ToTable method. In the example, I checked what are the...
Read more >
Attribute 'Table' is not valid on this declaration type. It is ...
It is working in my colleague's system but text object not adding to table. Only Partition key and row key is adding. Jobject...
Read more >
Update Your Azure Functions Table Storage Bindings
The table storage bindings in Azure Functions have changed quite a bit recently and that can result in previously working code no longer...
Read more >
Frequently Asked Questions
Short answer: A column declared INTEGER PRIMARY KEY will autoincrement. Longer answer: If you declare a column of a table to be INTEGER ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found