0

I have a very small WPF executable that I want to be stand-alone. I've wittled the external dependencies down to a single MyApp.exe.config file. It needs this because I am using Entity Framework. Is there anyway I can configure this in code so that it can be compiled into my executable?

Here is my config file:

<?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>
    <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
    </startup>
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="System.Windows.Interactivity" publicKeyToken="31bf3856ad364e35" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.5.0.0" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
    <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">
            <parameters>
                <parameter value="System.Data.SqlServerCe.4.0" />
            </parameters>
        </defaultConnectionFactory>
        <providers>
            <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
            <provider invariantName="System.Data.SqlServerCe.4.0" type="System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact" />
        </providers>
    </entityFramework>
    <system.data>
        <DbProviderFactories>
            <remove invariant="System.Data.SqlServerCe.4.0" />
            <add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
        </DbProviderFactories>
    </system.data>
</configuration>
13
  • 1
    I agree and have cast a re-open vote on this. Commented Sep 18, 2014 at 15:21
  • 1
    If you are using EF6, This article has ifnormation on Code-Based configuration: msdn.microsoft.com/en-us/data/jj680699 Commented Sep 18, 2014 at 15:23
  • 2
    @Jordan: My bad. I must say I find your post very confusing. You are referring to 'stand alone' and the list of assemblies you have. I agreed on the question being duplicate. Commented Sep 18, 2014 at 15:27
  • 1
    I agree with patrick, if you are not tying to merge assemblies, what are you trying to do? Are asking how to get the information set up in the App.Config to be configured via code instead of in a external xml file? Commented Sep 18, 2014 at 15:28
  • 2
    But what do you mean by stand-alone? Commented Sep 18, 2014 at 15:34

2 Answers 2

3

The link provided in the comments by John Koerner solved my problem. For anyone who is looking for the solution here is the code that I used:

public class MyDbConfiguration : DbConfiguration
{
    public MyDbConfiguration()
    {
        SetDefaultConnectionFactory(new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0"));
        SetProviderServices("System.Data.SqlClient", SqlProviderServices.Instance);
        SetProviderServices("System.Data.SqlServerCe.4.0", SqlCeProviderServices.Instance);
    }
}

I just included this object in the same assembly as my DbContext. It worked wonderfully.

Sign up to request clarification or add additional context in comments.

Comments

0

You cannot configure this in code, but you can you ILMerge to merge the EF DLL (and any others you might need) into your exe. Here is an example of how to use ILMerge

1 Comment

Not at all what I am looking for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.