Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# .ToList()-该方法或操作未实现?_C#_Asp.net Mvc_Oracle_Entity Framework_Odp.net - Fatal编程技术网

C# .ToList()-该方法或操作未实现?

C# .ToList()-该方法或操作未实现?,c#,asp.net-mvc,oracle,entity-framework,odp.net,C#,Asp.net Mvc,Oracle,Entity Framework,Odp.net,我已经成功地使用MVC5/EF6创建了一个InventoryTracking应用程序,使用代码优先迁移来填充我的LocalDB文件中的一些测试数据。我现在正试图修改应用程序以使用Oracle DB,在该数据库中,我创建了与本地DB文件中驻留的表相同的表 经过大量的挖掘,我得到了为我的VS2013下载的Oracle开发工具(Zip文件:odtwithodadac121021)。然后,我使用NUGET安装了Oracle.ManagedDataAccess,这样它就可以与EF6一起使用了(显然,从一年

我已经成功地使用MVC5/EF6创建了一个InventoryTracking应用程序,使用代码优先迁移来填充我的LocalDB文件中的一些测试数据。我现在正试图修改应用程序以使用Oracle DB,在该数据库中,我创建了与本地DB文件中驻留的表相同的表

经过大量的挖掘,我得到了为我的VS2013下载的
Oracle开发工具
(Zip文件:
odtwithodadac121021
)。然后,我使用NUGET安装了Oracle.ManagedDataAccess,这样它就可以与EF6一起使用了(显然,从一年前的大多数文章来看,Oracle.DataAccess只与EF5一起使用)

我的Web.Config如下所示:

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=301880
  -->
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  <sectionGroup name="elmah">
      <section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />
      <section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
      <section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
      <section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" />
    </sectionGroup>
  <section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
  </configSections>
  <connectionStrings>
      <add name="Default" providerName="Oracle.ManagedDataAccess.Client" connectionString="DATA SOURCE=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=host_123)(PORT=1234)))(CONNECT_DATA=(SID=hostprd)(SERVER=DEDICATED)));MIN POOL SIZE=3;PASSWORD=123_syst;PERSIST SECURITY INFO=True;USER ID=Userid; Connection Lifetime=16; Connection Timeout=8" />
    <!--<add name="InventoryTrackerContext" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\InventoryTrackerDBDev-4.mdf;Initial Catalog=InventoryTrackerDBDev-4;Integrated Security=True" providerName="System.Data.SqlClient" />-->
  </connectionStrings>
  <appSettings>
      <add key="DefaultConnection" value="Default" />
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    <add key="MvcSiteMapProvider_IncludeAssembliesForScan" value="InventoryTracker" />
    <add key="MvcSiteMapProvider_UseExternalDIContainer" value="false" />
    <add key="MvcSiteMapProvider_ScanAssembliesForSiteMapNodes" value="true" />
  </appSettings>
  <system.web>
    <!-- Active Directory Authentication - http://www.asp.net/mvc/overview/older-versions-1/security/authenticating-users-with-windows-authentication-cs -->
    <authentication mode="Windows" />
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
    <httpModules>
      <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Extensibility.Web.RequestTracking.WebRequestTrackingModule, Microsoft.ApplicationInsights.Extensibility.Web" />
    <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" /><add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" /><add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" /></httpModules>
    <pages>
      <namespaces>
        <add namespace="GridMvc" />
        <add namespace="MvcSiteMapProvider.Web.Html" />
        <add namespace="MvcSiteMapProvider.Web.Html.Models" />
      </namespaces>
    </pages>
  </system.web>
  <system.webServer>
      <!--
      http errors allows us to override default errors.
      errorMode="Custom" means that IIS will always serve our custom pages.
      if you want to see details while in develoment mode, set to DetailedLocalOnly.
      for this demo, we have it set to Custom.
    -->
      <httpErrors errorMode="Custom" existingResponse="Replace">
          <remove statusCode="404" />
          <remove statusCode="500" />
          <error statusCode="404" responseMode="ExecuteURL" path="/Error/NotFound" />
          <error statusCode="500" responseMode="ExecuteURL" path="/Error/Error" />
      </httpErrors>  
    <modules>
      <remove name="FormsAuthentication" />
      <remove name="ApplicationInsightsWebTracking" />
      <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Extensibility.Web.RequestTracking.WebRequestTrackingModule, Microsoft.ApplicationInsights.Extensibility.Web" preCondition="managedHandler" />
      <remove name="UrlRoutingModule-4.0" />
      <add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" />
      <remove name="BundleModule" />
      <add name="BundleModule" type="System.Web.Optimization.BundleModule" />
    <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" /><add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" /><add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" /></modules>
    <validation validateIntegratedModeConfiguration="false" />
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-5.2.0.0" newVersion="5.2.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebMatrix.Data" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <publisherPolicy apply="no" />
        <assemblyIdentity name="Oracle.ManagedDataAccess" publicKeyToken="89b483f429c47342" culture="neutral" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <entityFramework>
    <contexts>
      <context type="InventoryTracker.DAL.InventoryTrackerContext, InventoryTracker">
        <databaseInitializer type="InventoryTracker.DAL.InventoryInitializer, InventoryTracker" />
      </context>
    </contexts>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
      <provider invariantName="Oracle.ManagedDataAccess.Client" type="Oracle.ManagedDataAccess.EntityFramework.EFOracleProviderServices, Oracle.ManagedDataAccess.EntityFramework, Version=6.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
    </providers>
  </entityFramework>
  <elmah>
    <!--
        See http://code.google.com/p/elmah/wiki/SecuringErrorLogPages for 
        more information on remote access and securing ELMAH.
    -->
    <security allowRemoteAccess="false" />
  </elmah><location path="elmah.axd" inheritInChildApplications="false">
    <system.web>
      <httpHandlers>
        <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
      </httpHandlers>
      <!-- 
        See http://code.google.com/p/elmah/wiki/SecuringErrorLogPages for 
        more information on using ASP.NET authorization securing ELMAH.

      <authorization>
        <allow roles="admin" />
        <deny users="*" />  
      </authorization>
      -->
    </system.web>
    <system.webServer>
      <handlers>
        <add name="ELMAH" verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" preCondition="integratedMode" />
      </handlers>
    </system.webServer>
  </location>
  <system.data>
    <DbProviderFactories>
      <remove invariant="Oracle.ManagedDataAccess.Client" />
      <add name="ODP.NET, Managed Driver" invariant="Oracle.ManagedDataAccess.Client" description="Oracle Data Provider for .NET, Managed Driver" type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
    </DbProviderFactories>
  </system.data>
  <oracle.manageddataaccess.client>
    <version number="*">
      <dataSources>
        <dataSource alias="SampleDataSource" descriptor="(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORCL))) " />
      </dataSources>
    </version>
  </oracle.manageddataaccess.client>
</configuration>
库存初始值设定项

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using InventoryTracker.Models;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using InventoryTracker.DAL;
using Oracle.ManagedDataAccess.Client;
using System.Configuration;

namespace InventoryTracker.DAL
{
    public class InventoryTrackerContext : DbContext
    {
        public InventoryTrackerContext()
            //: base("InventoryTrackerContext")
            : base( new OracleConnection(ConfigurationManager.ConnectionStrings["Default"].ConnectionString), true)
        {

        }

        public DbSet<INV_Assets> INV_Assets { get; set; }
        public DbSet<INV_Models> INV_Models { get;set; }
        public DbSet<INV_Manufacturers> INV_Manufacturers { get;set; }
        public DbSet<INV_Types> INV_Types { get; set; }
        public DbSet<INV_Locations> INV_Locations { get; set; }
        public DbSet<INV_Vendors> INV_Vendors { get; set; }
        public DbSet<INV_Statuses> INV_Statuses { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
             modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
             modelBuilder.Entity<INV_Assets>().MapToStoredProcedures();
        }

        public System.Data.Entity.DbSet<InventoryTracker.Models.INV_Owners> INV_Owners { get; set; }

        public System.Data.Entity.DbSet<InventoryTracker.Models.INV_AssetsHistory> INV_AssetsHistory { get; set; }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using InventoryTracker.Models;
using InventoryTracker.DAL;
using WebMatrix.WebData;

namespace InventoryTracker.DAL
{
    public class InventoryInitializer : System.Data.Entity.DropCreateDatabaseIfModelChanges<InventoryTrackerContext>
    {
        InventoryTrackerContext context = new InventoryTrackerContext();

        protected override void Seed(InventoryTrackerContext context)
        {
            List<INV_Locations> invLocs = getLocations();
            invLocs.ForEach(s => context.INV_Locations.Add(s));
            List<INV_Manufacturers> invManufacturers = getManufacturers();
            invManufacturers.ForEach(s => context.INV_Manufacturers.Add(s));
            List<INV_Models> invModels = getModels();
            invModels.ForEach(s => context.INV_Models.Add(s));
            List<INV_Statuses> invStatuses = getStatuses();
            invStatuses.ForEach(s => context.INV_Statuses.Add(s));
            List<INV_Types> invTypes = getTypes();
            invTypes.ForEach(s => context.INV_Types.Add(s));
            List<INV_Vendors> invVendors = getVendors();
            invVendors.ForEach(s => context.INV_Vendors.Add(s));

            List<INV_Assets> invAssets = getAssets();
            invAssets.ForEach(s => context.INV_Assets.Add(s));

            context.SaveChanges();
        }

        // SEED CODE THAT DOESN'T APPEAR TO RUN? THIS FILE IS REFERENCED IN WEB.CONFIG
    }
}
namespace InventoryTracker.Migrations
{
    using System;
    using System.Collections.Generic;
    using System.Data.Entity;
    using System.Data.Entity.Migrations;
    using System.Linq;
    using System.Web;
    using System.Globalization;
    using InventoryTracker.Models;
    using InventoryTracker.DAL;
    using WebMatrix.WebData;

    internal sealed class Configuration : DbMigrationsConfiguration<InventoryTracker.DAL.InventoryTrackerContext>
    {
        public Configuration()
        {
            AutomaticMigrationsEnabled = false;
        }

        protected override void Seed(InventoryTracker.DAL.InventoryTrackerContext context)
        {
List<INV_Locations> invLocs = getLocations();
            context.INV_Locations.AddRange(invLocs);
            context.SaveChanges();
            List<INV_Manufacturers> invManufacturers = getManufacturers();
            context.INV_Manufacturers.AddRange(invManufacturers);
            context.SaveChanges();
            List<INV_Models> invModels = getModels();
            context.INV_Models.AddRange(invModels);
            context.SaveChanges();
            List<INV_Statuses> invStatuses = getStatuses();
            context.INV_Statuses.AddRange(invStatuses);

            context.SaveChanges();

            List<INV_Types> invTypes = getTypes();
            context.INV_Types.AddRange(invTypes);
            context.SaveChanges();
            List<INV_Vendors> invVendors = getVendors();
            context.INV_Vendors.AddRange(invVendors);

            context.SaveChanges();

            List<INV_Assets> invAssets = getAssets();
            context.INV_Assets.AddRange(invAssets);

            List<INV_AssetsHistory> invAssetsHistory = getAssetHistories();
            context.INV_AssetsHistory.AddRange(invAssetsHistory);

            context.SaveChanges();
        }

        // Various GET() Code, this is where the Seeding DOES Occur as opposed to file above.
}
当我在Web.config中为
InventoryTrackerContext
定义了连接字符串后,我可以简单地创建新迁移(
addmigration InitialCreate
),然后运行(
updatedatabase
)以使用我在Configuration.cs中指定的数据为本地数据库文件种子

现在,我试图使用我的
ORACLE
连接
[“Default”]
并通过类似的上下文进行访问,我遇到了一些问题。我创建了一个新的迁移,但当我尝试运行(
更新数据库
)时,我收到以下消息:

PM> update-database
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
Applying explicit migrations: [201503251604557_InitialCreate].
Applying explicit migration: 201503251604557_InitialCreate.
System.NotImplementedException: The method or operation is not implemented.
   at Oracle.ManagedDataAccess.EntityFramework.OracleMigrationSqlGenerator.Generate(CreateProcedureOperation createProcedureOperation)
   at CallSite.Target(Closure , CallSite , OracleMigrationSqlGenerator , Object )
   at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid2[T0,T1](CallSite site, T0 arg0, T1 arg1)
   at CallSite.Target(Closure , CallSite , OracleMigrationSqlGenerator , Object )
   at Oracle.ManagedDataAccess.EntityFramework.OracleMigrationSqlGenerator.<GenerateStatements>b__2(Object op)
   at Oracle.ManagedDataAccess.EntityFramework.EntityUtils.Each[T](IEnumerable`1 ts, Action`1 action)
   at Oracle.ManagedDataAccess.EntityFramework.OracleMigrationSqlGenerator.GenerateStatements(IEnumerable`1 migrationOperations)
   at Oracle.ManagedDataAccess.EntityFramework.OracleMigrationSqlGenerator.Generate(IEnumerable`1 migrationOperations, String providerManifestToken)
   at System.Data.Entity.Migrations.DbMigrator.GenerateStatements(IList`1 operations, String migrationId)
   at System.Data.Entity.Migrations.Infrastructure.MigratorBase.GenerateStatements(IList`1 operations, String migrationId)
   at System.Data.Entity.Migrations.DbMigrator.ExecuteOperations(String migrationId, XDocument targetModel, IEnumerable`1 operations, IEnumerable`1 systemOperations, Boolean downgrading, Boolean auto)
   at System.Data.Entity.Migrations.DbMigrator.ApplyMigration(DbMigration migration, DbMigration lastMigration)
   at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.ApplyMigration(DbMigration migration, DbMigration lastMigration)
   at System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
   at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
   at System.Data.Entity.Migrations.DbMigrator.UpdateInternal(String targetMigration)
   at System.Data.Entity.Migrations.DbMigrator.<>c__DisplayClassc.<Update>b__b()
   at System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
   at System.Data.Entity.Migrations.Infrastructure.MigratorBase.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
   at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
   at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String targetMigration)
   at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.Run()
   at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
   at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
   at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
   at System.Data.Entity.Migrations.Design.ToolingFacade.Update(String targetMigration, Boolean force)
   at System.Data.Entity.Migrations.UpdateDatabaseCommand.<>c__DisplayClass2.<.ctor>b__0()
   at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
The method or operation is not implemented.

谁能看出我哪里出了问题?我正试图通过
上下文
变量和实体框架访问我的ORACLE
db
,就像我对本地db文件所做的那样。

ToList
不是您的问题。查看堆栈跟踪-错误是由数据库迁移器引发的。@DStanley,我也这么想过,但当我尝试使用
.ToList()
行标记运行应用程序时,我认为(不知何故)它们可能相关。您对如何解决迁移问题有什么建议吗?通过
Server Explorer
了解,我知道我的新连接字符串正在运行,但我不知道它是否在我的
db
上下文变量中正确使用,就像我如何使用我以前的本地db文件连接字符串一样。理想情况下(如果可能的话),我希望我在本地DB文件上运行的
Seed()
方法在ORACLE DB表中生效——尽管我总是可以编写该部分的脚本,而不是尝试处理数据类型映射。您下载了哪个Nuget包?确保标题中有“官方”一词的“官方”一词:它负责配置您的项目。非官方的没有EF的配置。@ChristianShay,我有两个引用-
Oracle.ManagedDataAccess
&
Oracle.ManagedDataAccess.EntityFramework
来自“官方”nuget:
namespace InventoryTracker.Controllers
{
    public class HomeController : Controller
    {
        InventoryTrackerContext _db = new InventoryTrackerContext();
        public ActionResult Index(INV_Assets defModel)
        {
            var assetList = _db.INV_Assets.ToList();
            return View(assetList);
            //return View(defModel);
        }