开发者

Visual C# Express and Oracle database Express using entity framework

I'm trying to access my Oracle XE database using Visual C# Express and entity framework.

I've tried installing oracleef (http://oracleef.codeplex.com/) but I'm not getting Oracle EF provider inside Visual C# Express add EF connection wizard, although machine.config contains

<DbProviderFactories>
  <add name="Oracle Data Provider for .NET" invariant="Oracle.DataAccess.Client" description="Oracle Data Provider for .NET" type="Oracle.DataAccess.Client.OracleClientFactory, Oracle.DataAccess, Version=4.112.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
  <add name="Microsoft SQL Server Compact Data Provider" invariant="System.Data.SqlServerCe.3.5" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=3.5.0.0, Culture=neutral, PublicKeyToken=开发者_如何学编程89845dcd8080cc91" />
</DbProviderFactories>

I've tried using EdmGen2.exe to manually generate EF classes from database, but I had little success.

How can I use Oracle database, Visual C# Express and Entity Framework together?


VS Express doesn't support third party components such as DB connection wizards. You will have to configure the connection manually (and create the entity model manually, too... so I suggest you use EF Code First)


You could install the oracle Instant Client with ODP.Net and add Oracle.DataAccess as reference to your project. After that you could connect to your database, like this:

using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;

private OracleConnection Connect = new OracleConnection();

public int OracleConnect(string hostname, string username, string password, string servicename)
{
    Connect.ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=" + hostname + ") (PORT=1521))(CONNECT_DATA=(SERVICE_NAME=" + servicename + ")));" + "User Id=" + username + ";Password=" + password + ";";
    try
    {
        Connect.Open();
        return 0;

    }
    catch (OracleException OracleExeption)
    {
        return -1;
    }
}   
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜