Posts o[vsexpress+mysql] asp.net using entity framework with mysql on visual studio express (old)
Post
Cancel

o[vsexpress+mysql] asp.net using entity framework with mysql on visual studio express (old)

reference http://www.rssbus.com/kb/articles/ado-entityframework-manual.rst https://msdn.microsoft.com/en-us/library/bb896270(v=vs.100).aspx https://social.msdn.microsoft.com/Forums/en-US/e2d6f829-0703-47cc-b23a-25f563c25712/adonet-entity-framwork-the-specified-metadata-path-is-not-valid?forum=adodotnetentityframework

What is Entity Framework?

http://www.codeproject.com/Articles/676309/ADO-NET-Entity-Framework-Interview-Questions

the problem: cant use mysql-connector doesnt appear on connection dialog!!

VSExpress users continue reading the article VSPro for 2010 you must install mysql-connector-net-6.6.5.msi, tested&working (src - http://stackoverflow.com/questions/4235291/how-to-connect-to-a-mysql-data-source-in-visual-studio) VSPro above use MySQL for Visual Studio

snap309

1-download&install latest mysql-connector http://download.softagency.net/MySQL/Downloads/Connector-Net/ (tested with mysql-connector-net-6.9.7.msi, tried also with mysql-connector-net-6.3.4 but failed!) 2-run your mysql instance, you must have already a database and some tables on it 3-open cmd goto : %windir%\Microsoft.NET\Framework\v4.0.30319
4-execute at cmd :

1
edmgen.exe /provider:MySql.Data.MySqlClient /mode:fullgeneration /c:"Data Source=localhost;Initial Catalog=testdb2;User ID=x;Password=x;" /project:School /entitycontainer:SchoolEntities /namespace:SchoolModel /language:CSharp

^this one will generate 5files! snap305

drop all to your project!

snap306

the tagged^ files School.csdl / School.msl / School.ssdl must have Build Action : Embedded Resource and other 2 Build Action : Compile…

snap307

then add the connection string to your web.config (you will use it on ~every page, right?) WARNING must append in front of csdl/ssdl/msl filenames the PRJ Namespace! example :

1
2
3
4
5
6
7
8
9
<configuration>
    <system.web>
        <compilation debug="true" targetframework="4.0"></compilation>
      <pages enableviewstate="false"></pages>
    </system.web>
    <connectionstrings>
      <add name="SchoolEntities" connectionstring="metadata=res://*/WebApplication1.School.csdl|res://*/WebApplication1.School.ssdl|res://*/WebApplication1.School.msl;provider=MySql.Data.MySqlClient;provider connection string='Data Source=localhost;Initial Catalog=x;User ID=x;Password=x'"></add>
    </connectionstrings>
</configuration>

5-use EdmGen2 to generate the .edmx from ^4files…

then on webform1.aspx

1
2
3
4
5
6
7
8
9
10
string conn = System.Configuration.ConfigurationManager.ConnectionStrings["SchoolEntities"].ConnectionString;

SchoolModel.SchoolEntities env = new SchoolModel.SchoolEntities(conn);

var queryRet = from p in env.bubbles select p;

foreach (var results in queryRet)
{
    Console.WriteLine(results.id);
}

5-Add reference to your VS PRJ, System.Data.Entity.dll + System.Runtime.Serialization.dll > F5!

snap308

yeah is working.. :)

origin - http://www.pipiscrew.com/?p=2216 vsexpressmysql-asp-net-using-entity-framework-with-mysql-on-visual-studio-express

This post is licensed under CC BY 4.0 by the author.
Contents

Trending Tags