Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/308.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# 我不能将Code First fluent API与.NET Portable一起使用吗?_C#_Entity Framework_Visual Studio 2015_Portable Class Library_Ef Fluent Api - Fatal编程技术网

C# 我不能将Code First fluent API与.NET Portable一起使用吗?

C# 我不能将Code First fluent API与.NET Portable一起使用吗?,c#,entity-framework,visual-studio-2015,portable-class-library,ef-fluent-api,C#,Entity Framework,Visual Studio 2015,Portable Class Library,Ef Fluent Api,我已经创建了一个针对.NETPortable的可移植类库,v4.0 下课 public class AddressConfiguration : EntityTypeConfiguration<Address> { public AddressConfiguration() { ToTable("Addresses"); HasKey(c => c.Id); } }

我已经创建了一个针对.NETPortable的可移植类库,v4.0

下课

public class AddressConfiguration : EntityTypeConfiguration<Address>
    {
        public AddressConfiguration()
        {
            ToTable("Addresses");
            HasKey(c => c.Id);
        }
    }
我错过了什么

App.config是


这里的错误有点误导。当您刚刚通过NuGet安装EF时:

安装包EntityFramework

NuGet将报告它已安装:

Adding package 'EntityFramework.6.1.3' to folder '\\psf\home\Documents\Visual Studio 2015\Projects\Solution2\packages'
Added package 'EntityFramework.6.1.3' to folder '\\psf\home\Documents\Visual Studio 2015\Projects\Solution2\packages'
Added package 'EntityFramework.6.1.3' to 'packages.config'
Executing script file '\\psf\home\Documents\Visual Studio 2015\Projects\Solution2\packages\EntityFramework.6.1.3\tools\init.ps1'
Executing script file '\\psf\home\Documents\Visual Studio 2015\Projects\Solution2\packages\EntityFramework.6.1.3\tools\install.ps1'
上面的两个脚本将修改proj文件和app.config以及package.config文件,但是不会引用实际的dll

如果检查packages\EntityFramework.6.1.3\lib的内容,您会发现两个包含二进制文件net40和net45的文件夹

事实上,EF根本不支持可移植配置文件。你可能想考虑使用EF7.

您可能手动引用了.NET40或.NET45 DLL之一。现在您面临着API不匹配的问题

另一个选择是重新考虑应用程序的体系结构。您可以将业务逻辑保留在PCL中,使用存储抽象出工作,并将抽象注入到业务逻辑类中

上述抽象的实际实现必须保留在.NET4.5项目中


不知道你的项目的任何细节,这就是我所能建议的。

错误是什么?@Nikolaus你是什么意思?我已经将其包含在问题中,您使用哪一版本的VS?@Nikolaus 2015。您可以将您的project.csproj添加到列出所有参考的位置吗?
<?xml version="1.0" encoding="utf-8"?>
<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" />
  </configSections>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>
<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="EntityFramework" version="6.1.3" targetFramework="portable40-net45+sl5" />
</packages>
Adding package 'EntityFramework.6.1.3' to folder '\\psf\home\Documents\Visual Studio 2015\Projects\Solution2\packages'
Added package 'EntityFramework.6.1.3' to folder '\\psf\home\Documents\Visual Studio 2015\Projects\Solution2\packages'
Added package 'EntityFramework.6.1.3' to 'packages.config'
Executing script file '\\psf\home\Documents\Visual Studio 2015\Projects\Solution2\packages\EntityFramework.6.1.3\tools\init.ps1'
Executing script file '\\psf\home\Documents\Visual Studio 2015\Projects\Solution2\packages\EntityFramework.6.1.3\tools\install.ps1'