Closed ClarkHsu closed 5 years ago
Hello @ClarkHsu ,
We will look at it but I'm afraid that even if we fix it you will still have the issue.
If we fix it for EF Classic
, the issue will keep being raise probably for EF6
.
I have assigned a developer to check it.
Best Regards,
Jonathan
Hello @ClarkHsu ,
We successfully reproduced the issue.
Obviously, we don't expect both projects are used in the same project.
One problem is that both libraries share the same config section <entityFramework>
One solution on your side is to have different config depending if you use Entity Framework
or Entity Framework Classic
since library name & version are different.
Perharp a better solution that we tested could be to allow you to customize the config section such as:
EntityFrameworkManager.ConfigSectionName = "entityFrameworkClassic";
and providing a config file like this:
<configuration>
<configSections>
<section name="entityFrameworkClassic" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, Z.EntityFramework.Classic, Version=7.0.0.0, Culture=neutral, PublicKeyToken=afc61983f100d280" requirePermission="false" />
</configSections>
<entityFrameworkClassic>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, Z.EntityFramework.Classic">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, Z.EntityFramework.Classic.SqlServer" />
</providers>
</entityFrameworkClassic>
</configuration>
It's something that would work for you?
Hi Jonathan, Thanks for your quick response!
I believe letting us to config the section sounds good.
Cheers, Clark
Great,
We will release a version supporting it tomorrow night.
Hello @ClarkHsu ,
The v7.0.18 has been released.
You can now specify a section name by using the ConfigSectionName
options.
Examples:
Z.EntityFramework.Classic.EntityFrameworkManager.ConfigSectionName = "entityFrameworkClassic";
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<section name="entityFrameworkClassic" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, Z.EntityFramework.Classic, Version=7.0.0.0, Culture=neutral, PublicKeyToken=afc61983f100d280" requirePermission="false" />
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<entityFrameworkClassic>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, Z.EntityFramework.Classic">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, Z.EntityFramework.Classic.SqlServer" />
</providers>
</entityFrameworkClassic>
</configuration>
Let me know if everything works as expected.
Best Regards,
Jonathan
Hi Jonathan, Thumbs up for your quick action!
Indeed, 7.0.18 has eliminated the exception as title describe, but it still not works by other issues. Condition1 (exactly using your config), will get
No Entity Framework provider found for the ADO.NET provider with invariant name 'Effort.Provider'. Make sure the provider is registered in the 'entityFramework' section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
at System.Data.Entity.Infrastructure.DependencyResolution.DefaultProviderServicesResolver.GetService(Type type, Object key)
at System.Data.Entity.Infrastructure.DependencyResolution.CachingDependencyResolver.<>c__DisplayClass1.<GetService>b__0(Tuple`2 k)
since it's finding the provider 'Effort.Provider', I changed the config to Condition2
<providers>
<provider invariantName="Effort.Provider" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
changes are only in
Unable to cast object of type 'Effort.Provider.EffortConnection' to type 'System.Data.SqlClient.SqlConnection'.
at System.Data.SqlClient.SqlCommand.set_DbConnection(DbConnection value)
at System.Data.Common.DbCommand.set_Connection(DbConnection value)
at System.Data.Entity.Internal.InterceptableDbCommand.set_DbConnection(DbConnection value)
at System.Data.Common.DbCommand.set_Connection(DbConnection value)
also an attempt to using Condition3
<provider invariantName="Effort.Provider" type="System.Data.Entity.SqlServer.SqlProviderServices, Z.EntityFramework.Classic.SqlServer" />
but, got
The 'Instance' member of the Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, Z.EntityFramework.Classic.SqlServer, Version=7.0.0.0, Culture=neutral, PublicKeyToken=afc61983f100d280' did not return an object that inherits from 'System.Data.Entity.Core.Common.DbProviderServices'. Entity Framework providers must inherit from this class and the 'Instance' member must return the singleton instance of the provider. This may be because the provider does not support Entity Framework 6 or later; see http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
at System.Data.Entity.Infrastructure.DependencyResolution.ProviderServicesFactory.GetInstance(Type providerType)
test code is :
public void TestMethod1()
{
EntityFrameworkManager.ConfigSectionName = "entityFramework";
var dbConnection = DbConnectionFactory.CreateTransient();
TestContext context = new TestContext(dbConnection);
var category = context.TestCategories.Add(new TestCategory { Name = "123", Description = "one two three" });
}
internal class TestContext: DbContext
{
static TestContext()
{
}
public TestContext(DbConnection dbConnection)
: base(dbConnection, false)
{ }
}
It seems no matter when I touch the EF6 things, issues will be raised by it. Could you evaluate whether it can be fixed - by any other small-scale code changes- at your side?
Cheers, Clark
Thank Clark for reporting,
We will look at how to make it work with Effort
.
Hello @ClarkHsu ,
Unfortunately, we are not able to reproduce the Condition1
.
The Condition2
and Condition3
are expected error since the Effort.Provider is not a SQL Connection
.
With Z.EntityFramework.Effort
, did you used the following package: https://www.nuget.org/packages/Z.EntityFramework.Classic.Effort/
You cannot use Effort.EF6
with EF Classic
since the Effort package has been built with EF
and not EF Classic
. Perharp that's the issue?
Best Regards,
Jonathan
Hi Jonathan, Could you please try this piece of code?
[TestMethod]
public void TestMethod1()
{
EntityFrameworkManager.ConfigSectionName = "entityFramework";
var dbConnection = DbConnectionFactory.CreateTransient();
TestContext context = new TestContext(dbConnection);
var category = context.TestCategories.Add(new TestCategory { Name = "123", Description = "one two three" }); //Exception thrown here
}
and use System.Data.Entity.DbContex as the base class of context
internal class TestContext: System.Data.Entity.DbContex
{
public DbSet<TestCategory> TestCategories { get; set; }
public TestContext(DbConnection dbConnection)
: base(dbConnection, false)
{ }
}
public class TestCategory
{
public short Id { get; set; }
public string Name { get; set; }
}
Cheers, Clark
Still working great,
I will make my developer try it tomorrow and we will provide you with a project if we are still unable to reproduce it.
Hello @ClarkHsu ,
I believe we successfully reproduced the issue.
After digging in some issue on Effort
, I found one similar to your: https://github.com/zzzprojects/EntityFramework-Effort/issues/42#issuecomment-274920079
We are currently looking about how we can make a solution that will not involve code on your side.
Hello @ClarkHsu ,
We didn't success to make it works without additional code but that's certainly something we will continue to dig over next week.
The issue happens normally when an EF Classic context is initialized and the Effort
provider has not been yet registered. The provider cannot anymore be registered and that cause the issue.
One way to make it works in unit tests is making sure the Effort.Provider.EffortProviderConfiguration.RegisterProvider();
is the first command called by the assembly. For example, by using the [AssemblyInitialize]
attribute.
[AssemblyInitialize]
public static void Initialize(Microsoft.VisualStudio.TestTools.UnitTesting.TestContext testContext)
{
Effort.Provider.EffortProviderConfiguration.RegisterProvider();
}
Let me know if you succesfully make it work or you need more help.
Best Regards,
Jonathan
Hi Jonathan, Sorry for my late response. But this solution's result is negative. Will still get error of
at System.Data.Entity.Infrastructure.DependencyResolution.DefaultProviderServicesResolver.GetService(Type type, Object key)
at System.Data.Entity.Infrastructure.DependencyResolution.CachingDependencyResolver.<>c__DisplayClass1.<GetService>b__0(Tuple`2 k)
And I am sure Effort.Provider.EffortProviderConfiguration.RegisterProvider();
is called at the very beginning using your hint of [AssemblyInitialize]
Cheers, Clark
Hello @ClarkHsu ,
Is the issue happen for Entity Framework
or Entity Framework Classic
? (or maybe both).
For EF Classic
, we already coded something that will automatically integrate EF Effort
. Only a few more test tomorrow is required before we release this fix.
Hello @ClarkHsu ,
Do you have an update on this issue?
Hello @ClarkHsu ,
This issue will be closed since we believe it's resolved.
If you have more information, feel free to provide it and we will re-open the issue.
Best Regards,
Jonathan
Hi there, I encountered this issue when a Unit test project using both EntityFramework and Z.EntityFramework.Classic.
nuget packages:
app.config:
have used ChangeAliases in *.csproj to resolve build errors:
exception throw when initial a context during run time:
so any clue of this? Cheers~