Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6985779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:43:27+00:00 2026-05-27T18:43:27+00:00

I would like to use Entity Framework Code first approach with SQLCE4 database. Everything

  • 0

I would like to use Entity Framework Code first approach with SQLCE4 database. Everything seems to be really nice but I have problem with debugging sql queries. I found that EFTracing from http://efwrappers.codeplex.com/ should be exactly what I need but I don’t know how to use it without app.config file. I am not big fan of this configuration. I want to use only C# code to set everything up and running. I think it should be fine to use code like this:

using (System.Data.Common.DbConnection c = 
    new EFTracingProvider.EFTracingConnection(
        new System.Data.SqlServerCe.SqlCeConnection(conn)))
{
    using (var context = new MyContext(c))
    {
        var a = from data in context.Projects select data;
    }
}

But it doesn’t work. It throws exception:

Unable to determine the provider name for connection of type
EFTracingProvider.EFTracingConnection’.

Is there any simple way how to correctly create wrapped connection only in code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:43:27+00:00Added an answer on May 27, 2026 at 6:43 pm

    Solution for my problem is following DbContext object.

    public class MyContext : DbContext
    {
      public MyContext()
        : base(CreateConnection("Data Source=file.sdf", 
                                "System.Data.SqlServerCe.4.0"), true)
      { }
    
      public DbSet<Project> Projects { get; set; }
    
      public static bool TraceEnabled = true;
    
      private static DbConnection CreateConnection(string connectionString, 
                                                   string providerInvariantName)
      {
        DbConnection connection = null;
        if (TraceEnabled)
        {
          EFTracingProviderConfiguration.RegisterProvider();
          EFTracingProviderConfiguration.LogToConsole = true;
          string wrapperConnectionString = String.Format(@"wrappedProvider={0};{1}",
             providerInvariantName, connectionString);
          connection = new EFTracingConnection() 
          { 
            ConnectionString = wrapperConnectionString 
          };
        }
        else
        {
          DbProviderFactory factory = DbProviderFactories.GetFactory(providerInvariantName);
          connection = factory.CreateConnection();
          connection.ConnectionString = connectionString;
        }
        return connection;
      }
    }
    

    So now I can use just context and connection is created automatically for wrapped or unwrapped SqlCe depending on TraceEnabled property.

    using (var context = new MyContext())
    {
        var a = context.Projects.FirstOrDefault();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the entity framework (code first). I would like to know if
I'm using ASP.NET MVC 3 with the Entity Framework 4 code first approach and
i use the entity framework code first for my application and i need a
I wish to use Entity Framework Code-first for a new project. So i decided
I'm using Entity Framework Code First. Usually I have no problem, but for a
I would like to be able to use Full text search in Code First
I would like to use a component that exposes the datasource property, but instead
I would like to use Emacs to edit some VB6 files but Emacs does
I would like to use VB9 but am not sure what syntax to use
I need a valid SQL Server 2008 connection string for Entity Framework 4.1 code-first

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.