OK, I have been working on this for several days and can't seem to resolve my problem. My intention is to ulimately use this in a wcf service, but for simplicity's sake, I am currently using a simple Console app for testing. I have the following in my Main
IUnityContainer container = new Unitycontainer();
var dao = container.Resolve<IMyDao>();
My config file has the unity configuration element
<section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration" />
I have also done the following rebinding to support a private deployment of SqlCE:
<assemblyIdentity name="System.Data.SqlServerCe" publicKeyToken="89845DCD8080CC91" culture="neutral" />
<bindingRedirect oldVersion="184.108.40.206-220.127.116.11" newVersion="18.104.22.168" />
I start the range at 22.214.171.124 because Entlib is compiled with SqlCe 3.5. I saw somewhere the suggestion I re-compile EntlLib with a reference to the 4.0 assembly; I did this, same result. I also put the
SqlCe DbProvider into the configuration:
<remove invariant="System.Data.SqlServerCe.4.0" />
<add name="Microsoft SQL Server Compact Data Provider 4.0"
description=".NET Framework Data Provider for Microsoft SQL Server Compact"
type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=126.96.36.199, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
Finally, here is the unity configuration in the config:
<extension type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Unity.EnterpriseLibraryCoreExtension, Microsoft.Practices.EnterpriseLibrary.Common" />
<register type="IMyDao, CETest" mapTo="MyDao, CETest">
<param name="database" dependencyName="MyDb" />
And of course, a connectionString:
<add name="MyDb" providerName="System.Data.SqlServerCe.4.0" connectionString="Data Source=MyDb.sdf" />
As you can see from the unity section, MyDao has a constructor which expects a database, and I am relying on the Entlib core extension to resolve this from "MyDb". The point is, this "works", except the resolved database object is always
of type GenericDatabase, not SqlCeDatabase. When I expand this in the debugger, I find that it even recognizes SqlCeDbProvider as its DbProvider, but it doesn't seem to matter, I get a GenericDatabase. I can go ahead and execute Sql against the 4.0 database,
and it actually works, but of course I can't access any SqlCe specific functions, like db.ExecuteResultSet().
This is driving me nuts. As mentioned above, re-compiling EntLib against the SqlCe 4.0 doesn't seem to make a difference. Also, if I just "new up" an SqlCeDatabase with my connections string, it all works, but I'm trying to get the container to
inject the same thing into MyDao. The other thing is that if I change the MyDb connection string to point to an ordinary Sql Server, I get an injected SqlDatabase, as expected.
So close, what am I missing here?