If the table name of the DB already exists is "mytable", I attribute it as follows, but it doesn't recognize it.
What should I do?
Hoge.cs
[Table("mytable")]
public class Hoge {
...
}
MyDbContext.cs
public class MyDbContext:DbContext{
public DbSet<Hoge>Hoge {get;set;}
...
}
Startup.cs
services.AddDbContext<MyDbContext>();
Internal Exception
Table'mydatabase.hoge'doesn't exist
I can only think of two things, but
The first is DbContext's OnModelCreating method.
modelBuilder.Entity<Hoge>().ToTable("Hoge");
You may have a code similar to .
This takes precedence, so you need to delete the ToTable.
Second, you may be using the wrong Table attribute on Hoge.cs.
using System.ComponentModel.DataAnnotations.Schema;
Do you use ↑ as the table attribute?
© 2024 OneMinuteCode. All rights reserved.