Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use Table attribute to map table name. #61

Open
redplane opened this issue May 8, 2017 · 2 comments
Open

Cannot use Table attribute to map table name. #61

redplane opened this issue May 8, 2017 · 2 comments

Comments

@redplane
Copy link

redplane commented May 8, 2017

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,

@SapientGuardian
Copy link
Owner

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");
    }

@redplane
Copy link
Author

redplane commented May 9, 2017

Yes, I've tried this method and it worked :)
But please take a look when you have time.

Thank you,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants