TableAttribute doesn't work, but .ToTable() works
See original GitHub issueNote: 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:
- Created 7 years ago
- Comments:10 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@avikenjale Sorry, I misread your message. Diego pointed you to the correct MySQL contact.
cc @gmartinezsan from the MySQL team as FYI.