Em Andamento

Problems with Microsoft Entity Framework & MySql

Our project needs ORM capability, supporting domain-driven / code-first development

Currently we are trying to use Microsoft Entity Framework CTP 5, with MySql Connector/Net version 6.3.5.

## Deliverables

# Problems with Microsoft Entity Framework and MySql

Our project needs ORM capability, supporting domain-driven / code-first development

Currently we are trying to use Microsoft Entity Framework CTP 5, with MySql Connector/Net version 6.3.5.

It seems that a portion of the functionality is not yet implemented.

## Cannot create database / tables

Given a DbContext object, such as:

public class BookCatalog : DbContext

{

public BookCatalog(string connectionString)

: base(connectionString)

{ }

public DbSet<Book> Books { get; set; }

}

And given some simple code such as

var context = new BookCatalog(connectionString);

var book = new Book

{

ISBN = "1111",

Title = "Intro to Code First",

FirstPublished = [url removed, login to view],

IsFiction = false

};

[url removed, login to view](book);

[url removed, login to view]();

The expected behaviour when calling [url removed, login to view]() is that it connects to the server specified in the connectionString, and creates a new database such as "BookCatalog" and the Book table if it does not already exist.

However, it instead fails with error The provider did not return a ProviderManifestToken string. and inner exception A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Shared Memory Provider, error: 40 - Could not open a connection to SQL Server)"

Clearly it is still trying to connect using SqlServer.

To correct this behaviour, we can create a MySqlConnectionFactory like this:

public sealed class MySqlConnectionFactory : IDbConnectionFactory

{

private readonly string _baseConnectionString;

public MySqlConnectionFactory()

{

throw new NotImplementedException();

}

public MySqlConnectionFactory(string baseConnectionString)

{

if (baseConnectionString == null)

{

throw new ArgumentNullException("baseConnectionString");

}

this._baseConnectionString = baseConnectionString;

}

public DbConnection CreateConnection(string nameOrConnectionString)

{

if (nameOrConnectionString == null)

{

throw new ArgumentNullException("nameOrConnectionString");

}

string connectionString = nameOrConnectionString;

if (![url removed, login to view]("="))

{

var databasename = [url removed, login to view](".", "_").Replace("+", "_");

MySqlConnectionStringBuilder builder = new MySqlConnectionStringBuilder([url removed, login to view]);

[url removed, login to view] = databasename;

connectionString = [url removed, login to view];

}

return new MySqlConnection(connectionString);

}

public string BaseConnectionString

{

get

{

return this._baseConnectionString;

}

}

}

And instruct the framework to use it instead of the default factory

[url removed, login to view] = new MySqlConnectionFactory(connectionString);

Having done this, the code now fails with the error Incorrect database name ''

If we pass in new database name then we get unknown database.

It seems unable to create a new database, because the connection process requires the database to already exist.

var context = new BookCatalog("EntityTest");

If we pass in an existing database, then the code continues to the [url removed, login to view]() command, which fails with the error Table '[url removed, login to view]' doesn't exist

Inspecting the database confirms that the books table has not been created.

If we add the line

[url removed, login to view]();

then it raises the error Can't create database 'entitytest'; database exists

and if we use a non-existant database name then we again get the error Unknown database

[url removed, login to view](true);

seems to do nothing - the database schema is unchanged.

Habilidades: Programação C#, Engenharia, MySQL, Gestão de projetos, Arquitetura de software, Teste de Software

Ver mais: idbconnectionfactory mysql, mysqlconnectionfactory, dbcontext mysqlconnectionfactory, entity framework mysql provider, connection string mysql entity framework, database defaultconnectionfactory mysql, string problems, do nothing management book, database error unable to connect to the database could not connect to mysql, base exception, 22 problems, mysqlconnectionfactory default connection factory, t-sql with, remote it management, public domain database, microsoft entity framework, framework microsoft, entity framework code first, net development books, sql microsoft, mysql to sql, Microsoft server, framework c, error establishing, entity framework

Acerca do Empregador:
( 5 comentários ) Birmingham, United States

ID do Projeto: #2995368

Premiar a:

aotechnolog

See private message.

$51 USD em 14 dias
(5 Avaliações)
2.5

2 freelancers estão ofertando em média $55 para este trabalho

suryavijayvw

See private message.

$58.65 USD in 14 dias
(121 Comentários)
5.7