Trace ADO.NET Entity Framework

摘要:Trace ADO.NET Entity Framework

參考連結:http://blogs.msdn.com/jkowalski/archive/2009/06/11/tracing-and-caching-in-entity-framework-available-on-msdn-code-gallery.aspx

第一步、下載程式(http://code.msdn.microsoft.com/EFProviderWrappers)

第二、在專案中加入參考EFTracingProvider.dll及EFProviderWrapperToolkit.dll。

第三、加入DbProviderFactories。

<system.data>

  <DbProviderFactories>

    <add name="EF Tracing Data Provider"

         invariant="EFTracingProvider"

         description="Tracing Provider Wrapper"

         type="EFTracingProvider.EFTracingProviderFactory, EFTracingProvider, Version=1.0.0.0, Culture=neutral, PublicKeyToken=def642f226e0e59b" />

    <add name="EF Generic Provider Wrapper"

         invariant="EFProviderWrapper"

         description="Generic Provider Wrapper"

         type="EFProviderWrapperToolkit.EFProviderWrapperFactory, EFProviderWrapperToolkit, Version=1.0.0.0, Culture=neutral, PublicKeyToken=def642f226e0e59b" />

  </DbProviderFactories>

</system.data>

第四、更改ConnectionString。

<connectionStrings>

  <add name="NorthwindEntities"

       connectionString="metadata=NorthwindEFModel.csdl | NorthwindEFModel.msl | NorthwindEFModel.Modified.ssdl;

                         provider=EFCachingProvider;

                         provider connection string=&quot;wrappedProvider=System.Data.SqlClient;Data Source=.\sqlexpress;
Initial Catalog=NorthwindEF;Integrated Security=True;MultipleActiveResultSets=True&quot;"

       providerName="System.Data.EntityClient" />

</connectionStrings>

 

 

第五、更改SSDL。

<?xml version="1.0" encoding="utf-8"?>
<Schema Namespace="NorthwindEFModel.Store"
  Alias="Self"
  Provider="EFCachingProvider"
  ProviderManifestToken="System.Data.SqlClient;2005"
  xmlns="http://schemas.microsoft.com/ado/2006/04/edm/ssdl">

完成。

如果不從Config去設定的話,可以繼承本來的Entities擴充來加入功能,可以參考原文程式的ExtendedNorthwindEntities.cs