Reputation: 2030
I am creating an MVC application with MySQL as backend. I am planning to use Entity Framework to work with this database. I already have a database so need to generate models from a database
Environment:
MySQL Server 5.7.21 MySQL for Visual Studio 1.27 Connector/NET 6.10.5 Visual Studio 2015
To Reproduce Issue:
Step 1: Add new item 'Ado.net Entity Data Model' Step 2: Selected 'EF Designer from database' and click 'Next' Step 3: Clicked 'New Connection'
There is no mysql connector available.
Other Details:
In Visual Studio 2015 and 17 initial time it shows the provider. when I tried next time it's not displaying Please help. I am checking this for 2 days
Upvotes: 8
Views: 6034
Reputation: 1785
Could it be a 32bit vs 64bit problem?
Example: 64bit driver installed Visual studio is 32bit?
I have that problem all the time with oledb to Informix. your sofware will work perfectly in 64bit, but the tooling is 32bit.
Upvotes: 0
Reputation: 12034
To start working with VS 2013 and EF 6
Hope this helps a bit.
MySQL Connector/Net 6.8.1 Beta
Upvotes: 2
Reputation: 3455
As MaDOS mentioned, mySql is not realy supported. If you want to use EF anyway you have to do a code-first-attempt.
You have to write the mapping-classes, and tell EF that it should NOT change the db.
public class MySqlDbContext : DbContext
{
public DbSet<MyOrderClass> Orders { get; set; }
public MySqlDbContext(IDbConnection connection)
: base((DbConnection)connection, false)
{
Database.SetInitializer<MySqlDbContext>(null); // Disable db-changes by dbContext
}
}
You main Problem are the data-types. Outside the MS-world not all data-types are supported (Oracle also got some problems with DateTime). In example-class below the "Created"-column is handled as string, which always works. In your .Net-application, you have to implement "converter"-properties which map to the desired type.
[Table("TORDERS")]
public class MyOrderClass
{
[Column("ORDERID")]
public long Id { get; set; }
[Column("CREATED")]
public string CreatedString { get; set; }
[NotMapped]
public DateTime? Created
{
get
{
DateTime tmp;
if (DateTime.TryParse(this.CreatedString, out tmp))
return tmp;
return null;
}
set
{
this.CreatedString = value.HasValue ? value.Value.ToString("yyyy-MM-dd HH:mm:ss") : null;
}
}
}
static void Main(params string[] args)
{
MyOrderClass tmp = new MyOrderClass() { CreatedString = "2018-01-01 11:11:11"};
Console.WriteLine(tmp.Created.ToString()); // This is how you want to work
tmp.Created = null;
Console.WriteLine(tmp.CreatedString); // this is surely not what you want to do
tmp.Created = new DateTime(2018,02,02,10,10,10);
Console.WriteLine(tmp.CreatedString); // Check if setter works ;)
}
Im not uptodate which types work, but with this you'll always be able to use EF. We used it some time ago to access an existing db, which hat an awful db-schema anyway, because of the schema we hat to setup the datatypes anyway ;).
Upvotes: 0