-
Notifications
You must be signed in to change notification settings - Fork 302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Database constructor - bug when ProviderFactory is not set #293
Comments
I am having the same problem in .Net Core RC2. I would like to point out that if you open the connection (conn.Open()) before you create the Database object it will proceed with the query without having to provide the DbFactory. Either way I believe this is a bug that needs to be resolved. How is NPoco handling multiple connections? Is it still using a shared connection pool? |
I don't think this is a bug. Its functioning as expected. If you are providing a DbConnection object, you are required to open and close the connection itself. We will not open or close it for you. Multiple connections is multiple Database objects. The |
In fact the bug might be that you can pass the DbProviderFactory in to the constructor with a DbConnection |
Then if it is meant this way, I suggest it should recognize this 'different' initialization mode, automatically open and close connection if passed as not open to constructor. And Open/CloseSharedConn() should do nothing in this mode (or even throw exception). |
This is exactly what it does do. I have added an exception if you don't open it yourself now but what you have suggested is how it currently works. |
Would it be possible to add other constructors to make it more like the previous versions? I'm not an expert in this but here are two examples: 1)remove the DbProviderFactory 2)pass just the connection string and DbProviderFactory. Are there any plans on updating the documentation for this? I see how a lot of people just starting can be confused by the limited options in the constructor choices that are allowed for .Net Core. I believe that we will see a rise in the number of people trying it out but be overwhelmed because they were used to the old ways. The current example listed on the README.md (similar example in Wiki) is invalid for .Net Core:
Compare it to this which is valid for .Net Core:
At the end of the day if we can make it a little more intuitive like it has been for the previous .Net frameworks it can really go a long way for someone who is trying to figure out the other aspects of .Net Core. |
This has landed in Nuget 3.4.0. Core can do this as well as pass the connection in.
|
When you use constructor with connection parameter, any query will fail unless you provide the DbProviderFactory. The result is System.NullReferenceException in
function: OpenSharedConnectionImp(...)
line: _sharedConnection = _factory.CreateConnection();
how to reproduce:
The text was updated successfully, but these errors were encountered: