0

我創建了一個可移植類庫針對.NETPortable, v4.0我不能使用.NET Portable的Code First流利API嗎?

在下面的類

public class AddressConfiguration : EntityTypeConfiguration<Address> 
    { 
     public AddressConfiguration() 
     { 
      ToTable("Addresses"); 
      HasKey(c => c.Id); 
     } 
    } 

在行HasKey(c => c.Id); 視覺工作室抱怨

The type 'Expression<>' is defined in an assembly that is not referenced. 
You must add a reference to assembly 'System.Core, Version=4.0.0.0, Culture=neutral, 
PublicKeyToken=b77a5c561934e089'. 

我失去的是什麼?

App.config

<?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> 

packages.config

<?xml version="1.0" encoding="utf-8"?> 
<packages> 
    <package id="EntityFramework" version="6.1.3" targetFramework="portable40-net45+sl5" /> 
</packages> 
+0

什麼是錯誤? – Nikolaus

+0

@尼古拉斯你是什麼意思?我已將它包含在問題 – OrElse

+0

您使用哪個版本的VS? – Nikolaus

回答

1

錯誤是有點誤導這裏。當你剛剛通過的NuGet安裝EF:

Install-Package 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的內容,您會發現兩個帶有二進制文件的文件夾(net40net45)。

實際上,便攜式配置文件完全不受EF的支持。你可能想考慮使用EF7。

您可能手動引用了.NET40.NET45 DLL之一。現在,您在這裏遇到API不匹配的問題。

另一種選擇是重新考慮應用程序的體系結構。您可以將業務邏輯保留在PCL中,抽象出存儲的工作並將抽象注入到業務邏輯類中。

上面提到的抽象的實際實現必須保留在.NET 4.5項目中。

不知道任何有關您的項目的細節,這就是我所能建議的。