如何判断是否使用EF5

时间:2013-06-03 15:06:25

标签: entity-framework silverlight wcf-ria-services

我将从EF4到EF5的Silverlight / WCF RIA服务项目。目标是.NET4.5

这是一个尖峰 - 我正在使用DB First方法。即创建edmx,然后使用域服务类向导

enter image description here

到目前为止看起来很好

  • EntityFramework(5.0.0.0)
  • 此处的Microsoft.ServiceModel.DomainServices.EntityFramework(4.0.0.0)DbDomainService
  • System.Data.Entity(4.0.0.0)

与旧方式相反:

  • EntityFramework(5.0.0.0)
  • System.Data.Entity(4.0.0.0)
  • System.ServiceModel.DomainServices.EntityFramework(4.0.0.0)LinqToEntitiesDomainService in here

enter image description here

然后放了一个简单的UI来访问2表db并且它工作了 enter image description here

问题:此web.config不符合我的预期:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <sectionGroup name="system.serviceModel">
      <section name="domainServices" type="System.ServiceModel.DomainServices.Hosting.DomainServicesSection, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" allowDefinition="MachineToApplication" requirePermission="false" />
    </sectionGroup>
  </configSections>
  <system.web>
    <httpModules>
      <add name="DomainServiceModule" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    </httpModules>
    <compilation debug="true" targetFramework="4.5">
      <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </assemblies>
    </compilation>
   <!-- profile stuff commented out-->
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true">
      <add name="DomainServiceModule" preCondition="managedHandler" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    </modules>
  </system.webServer>
  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=(LocalDB)\v11.0;Initial Catalog=aspnet-BusinessApplication5.Web-20130603151851;Integrated Security=True" providerName="System.Data.SqlClient" />
    <add name="TestDBEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.\SQLEXPRESS;initial catalog=TestDB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
</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=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

从以下获得这些配置位。也许它们都是特定于代码的。 https://github.com/jeffhandley/riabooks

http://jeffhandley.com/archive/2012/12/10/RIA-Services-NuGet-Package-Updates-ndash-Including-Support-for-EntityFramework.aspx

http://mcasamento.blogspot.co.uk/2012/10/entity-framework-5-code-first-and-wcf.html

1 个答案:

答案 0 :(得分:2)

RIA Services dll是针对EF 4而不是EF5编译的,因此绑定Redirect用于使一切正常。如果RIA服务是开源的,那么将会有一个新的RiaServices.EntityFramework版本,它将针对EF 5和EF 6进行编译。开源的一个好处是能够输出尽可能多的NuGet包。支持所有组合。