SapientGuardian.EntityFrameworkCore.MySql
SapientGuardian.EntityFrameworkCore.MySql copied to clipboard
Cannot use Table attribute to map table name.
Hi there,
I'm currently facing an issue that I cannot map object to table name. For example. I have an object:
[Table("tram")]
public class Station
{
/// <summary>
/// Id of station.
/// </summary>
[Column("ID")]
public string Id { get; set; }
/// <summary>
/// Name of station.
/// </summary>
[Column("name")]
public string Name { get; set; }
/// <summary>
/// Name of station type.
/// </summary>
[Column("typename")]
public string TypeName { get; set; }
/// <summary>
/// Coordinate of station.
/// </summary>
[Column("name")]
public string Coordinate { get; set; }
/// <summary>
/// Address of station.
/// </summary>
[Column("diachi")]
public string Address { get; set; }
/// <summary>
/// Area which station belongs to.
/// </summary>
[Column("area")]
public string Area { get; set; }
/// <summary>
/// Phone number of station monitor.
/// </summary>
[Column("phone")]
public string Phone { get; set; }
}
When I did a query, I received an exception: MySql.Data.MySqlClient.MySqlException: Table 'localdb.Station' doesn't exist
Is it a bug or my wrong implementation ?
Thank you,
This seems to be a bug. I tried using an attribute to specify the table name and it was ignored for EnsureCreated as well. I'll look into this when I can. In the mean time, I think you should be able to use the fluent API, like
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Station>()
.ToTable("tram");
}
Yes, I've tried this method and it worked :) But please take a look when you have time.
Thank you,