Entity Framework Code First MySql Multiple-Fill Tables

I am using Microsoft Entity Framework with the first code to manage my data (with MySQL). I defined a POCO object, however, when I try to add data, it says that users do not exist. I looked in the database and created the User not Users table. How can i fix this? It drives me crazy!

Thank!

  public class User
 {
    [Key,Required]
    public int UserId { get; set; }

    [StringLength(20), Required]
    public string UserName { get; set; }

    [StringLength(30), Required]
    public string Password { get; set; }

    [StringLength(100), Required]
    public string EmailAddress { get; set; }

    [Required]
    public DateTime CreateDate { get; set; }

    [Required]
    public bool IsActive { get; set; }
}
+5
source share
3 answers

I haven't used MySQL with EF yet, but regardless, I think the solution is unbias. You must disable the Numbering Convention.

using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions.Edm.Db;

public class MyDbContext: DbContext
{
    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {    
        modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
    }
}

Now EF will look for a literal of the name of your object in the table name.

http://msdn.microsoft.com/en-us/data/aa937723 Continue Learning Entity Framework. , "" "".

: http://blogs.msdn.com/b/adonet/archive/2010/12/14/ef-feature-ctp5-fluent-api-samples.aspx

+3
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;

namespace YourNamespace
{
    public class DataContext : DbContext
    {
        protected override void OnModelCreating(DbModelBuilder dbModelBuilder)
        {
            dbModelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
        }

        public DbSet<User> User { get; set; }
    }
}
+4

, :

[Table("Users")]
public class User
{
    //...
}

... API. OnModelCreating DbContext.

public class MyDbContext : DbContext
{
    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity<User>().Map(t => t.ToTable("Users"));
    }
}

EF . , 4.1...

( MySQL...)

+2

All Articles