程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> ASP.NET >> 關於ASP.NET >> Entity Framework學習中級篇5—使EF支持Oracle9i

Entity Framework學習中級篇5—使EF支持Oracle9i

編輯:關於ASP.NET

從Code MSDN上下載下來的EFOracleProvider不支持Oracle9i.但是,目前我所使用的還是Oracle9i。為此,對EFOracleProvider修改了以下,以便使其支持Oracle9i.

下面說說具體修改地方.(紅色部分為添加或修改的代碼部分)

一,修改EFOracleProvider

1,修改EFOracleProviderManifest.cs類文件,

internal const string TokenOracle9i = "9i";//add by xray2005

internal const string TokenOracle10g = "10g";

internal const string TokenOracle11g = "11g";

以下兩個地方,不修改也是可以的.但考慮目前我主要是使用9i,所以也就修改成9i了.

private EFOracleVersion _version = EFOracleVersion.Oracle9i; //EFOracleVersion.Oracle11g;

private string _token = TokenOracle9i; //TokenOracle10g;

2,修改EFOracleVersion.cs類文件,如下代碼所示:

namespace EFOracleProvider

{

using System;

/// <summary>

/// This enum describes the current storage version

/// </summary>

internal enum EFOracleVersion

{

Oracle9i = 9, //add by xray2005

/// <summary>

/// Oracle10g

/// </summary>

Oracle10g = 10,



/// <summary>

/// Oracle 11g

/// </summary>

Oracle11g = 11,

// higher versions go here

}

/// <summary>

/// This class is a simple utility class that determines the version from the

/// connection

/// </summary>

internal static class EFOracleVersionUtils

{

/// <summary>

/// Get the version from the connection.

/// </summary>

/// <param name="connection">current connection</param>

/// <returns>version for the current connection</returns>

internal static EFOracleVersion GetStorageVersion(EFOracleConnection connection)

{

string serverVersion = connection.ServerVersion;

if (serverVersion.StartsWith("9."))

{

return EFOracleVersion.Oracle9i; //add by xray2005

}

else if (serverVersion.StartsWith("10."))

{

return EFOracleVersion.Oracle10g;

}

else if (serverVersion.StartsWith("11."))

{

return EFOracleVersion.Oracle11g;

}

throw new ArgumentException("Could not determine storage version; " +

"a valid storage connection or a version hint is required.");

}

internal static string GetVersionHint(EFOracleVersion version)

{

switch (version)

{

case EFOracleVersion.Oracle9i:

return EFOracleProviderManifest.TokenOracle9i; //add by xray2005

case EFOracleVersion.Oracle10g:

return EFOracleProviderManifest.TokenOracle10g;

case EFOracleVersion.Oracle11g:

return EFOracleProviderManifest.TokenOracle11g;

default:

throw new ArgumentException("Could not determine storage version; " +

"a valid storage connection or a version hint is required.");

}

}

internal static EFOracleVersion GetStorageVersion(string versionHint)

{

if (!string.IsNullOrEmpty(versionHint))

{

switch (versionHint)

{

case EFOracleProviderManifest.TokenOracle9i:

return EFOracleVersion.Oracle9i; //add by xray2005

case EFOracleProviderManifest.TokenOracle10g:

return EFOracleVersion.Oracle10g;

case EFOracleProviderManifest.TokenOracle11g:

return EFOracleVersion.Oracle11g;

}

}

throw new ArgumentException("Could not determine storage version; " +

"a valid storage connection or a version hint is required.");

}



internal static bool IsVersionX(EFOracleVersion storageVersion)

{

return storageVersion == EFOracleVersion.Oracle9i || storageVersion == EFOracleVersion.Oracle10g ||

storageVersion == EFOracleVersion.Oracle11g; //add by xray2005

}

}

}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved