Skip to content

Add initial support for ObjectContext.ExecuteFunction #129

Closed
wants to merge 97 commits into from

10 participants

@kenjiuno

It will allow you to call PostgreSQL's functions and stored procedures via EntityFramework support.

This is for 2.1 branch. And older PR #100 is replaced by this fix.

@roji roji referenced this pull request Dec 16, 2013
Closed

EF support improvement #100

@franciscojunior
Npgsql member
@roji
Npgsql member
roji commented Jan 2, 2014

Hi @kenjiuno, thanks for all the great work on EF support.

Is there any chance we can get some unit tests together on EF, like for this PR? To make EF support stable we really need a good suite of regression tests...

@kenjiuno
kenjiuno commented Jan 2, 2014

Hi, thanks for reply!

Yes, I'm willing to write the tests for it!

I'll wait for jjchiw's pull request #116. It contains good test for entity framework.

I'll append my tests after its merge.

@kenjiuno

Hi @roji

Is there any chance we can get some unit tests together on EF, like for this PR? To make EF support stable we really need a good suite of regression tests...

Thanks, I have added 2 tests.

  • GenerateObjectContext
  • ExecuteFunction

Because ObjectContext uses DBFirst model, I have added csdl/msl/ssdl files.

csdl/msl/ssdl files are generated by EdmGen06 against generated npgsql_tests_ef db. And then I have tweaked them manually.

My PostgreSQL is 9.3.1 x64 Windows 8.1. EntityFrameworkBasicTests will succeed on normal PostgreSQL instance (with no additional preparation).

franciscojunior and others added some commits Jul 21, 2014
@franciscojunior franciscojunior Update assembly version information to 2.2.0-beta1 a4d4e95
@franciscojunior franciscojunior Update Nuget versions to reflect beta1 release f3f3d21
@roji roji Unit test to reproduce #179
(cherry picked from commit bee2709)

(From #294)
d389f71
@roji roji Fix CommandBuilder event registration
CommandBuilder wasn't properly registering to its DataAdapter
events, resulting in bug #179

(cherry picked from commit 9940744)

(From #294)
8678469
Shay Rojansky Remove Postgresql 8.4. from unit tests
Fixes #297
051ea37
@roji roji Remove unused Web files cbf90f9
@roji roji Add doxyfile for doc generation
Fixed #285
8455f81
@roji roji Add doxygen outputdir to .gitignore f22a617
@roji roji Tweaks to doxygen 3c017db
@roji roji Unit test for #158 (prepared stmt leak) c429ad1
@roji roji Deallocate prepared statement on Dispose()
Note that this only happens in explicit Dispose()/
using, and not when Dispose() is called from a
finalizer (implementation for that is complicated).

Regardless, all prepared statements are automatically
deallocated when a connection is returned to the
connection pool (DISCARD ALL).

Fixes #158
46e2fe7
Shay Rojansky Prevent another prepared stmt leak
When a prepared command is re-prepared, the first
backend statement was not deallocated.

Noticed by @franciscojunior
b64e8bb
@franciscojunior franciscojunior Update Mono.Security.dll assembly to Mono version 3.4.0
Fix #264

(cherry picked from commit dad52aa)

(PR #273)
982f13f
@franciscojunior franciscojunior Backport #257 from master. d361070
@roji roji Repro unit test for #296
(cherry picked from commit b1a0378)

Backport #307 from master
ade5d7d
@glenebob glenebob Simplfied repro unit test bugs #240 and #296
This is about as simple as I can make it.

(cherry picked from commit 0d13218)

Backport #307 from master
2459774
@glenebob glenebob Fix for bugs #240 and #296
Properly handle escaped single quote character ('') in a quoted section during query parameter substitution.

(cherry picked from commit 253b6f9)

Backport #307 from master
caa9d3e
@glenebob glenebob Bugs #249 and #296 Unit Test Improvements
Use close approximations to the repro queries supplied for these bugs, in addition to the simple one devised for diagnosis.

(cherry picked from commit d45f620)

Backport #307 from master
10f10ff
@glenebob glenebob Remove debug/logging code.
(cherry picked from commit 5ec17bb)

Backport #307 from master
d85c56a
@franciscojunior franciscojunior Update assembly and nuget spec versions for RC1 release 5f5f95a
@Emill Emill EF: Fix INSERT INTO with no specified column values, by using DEFAULT…
… VALUES.

(cherry picked from commit e6c6bf6)

Backport #310 from master
1c6e2d2
@roji roji Changed nuspec to indicate Postgresql support
Used to say 7.x, changed to "9.x and above officially supported"
1546b8e
@Emill Emill Fix query parameter processing to more correctly match PostgreSQL's l…
…exer
14edc21
@Emill Emill Parameter substitution processing: if we detect multiple statements i…
…n a query that is not allowed, quit immediately. Also improve readability.
87b6e3e
@Emill Emill Parameter substitution processing: fix a small bug in dollar quoted s…
…tring processing.
67ef55a
@Emill Emill Parameter substitution processing: don't touch output parameters. 6b23357
@franciscojunior franciscojunior Remove Tools/vssdk*_tools/inc folder.
This folder contains only .h files which aren't used by Npgsql and takes a large space.

(cherry picked from commit 7092c6d)

Backport from #293
4245f8c
@franciscojunior franciscojunior Remove pdb files from Tools folder.
Those files aren't used and they only increase project size.

(cherry picked from commit c17fbdf)

Backported from master #318
d7d6b6a
@franciscojunior franciscojunior Update assembly and nuget spec versions for RC2 release 8f70c8b
@franciscojunior franciscojunior Update assembly and nuget spec versions for 2.2.0 final release 67c2449
@annymsMthd annymsMthd marked NpgsqlServices as public so it can be used in DbConfiguration …
…classes for EF.
617debc
@annymsMthd annymsMthd added directive to make NpgsqlServices public if it is being compiled…
… for EF 6
c972857
@franciscojunior franciscojunior Fix milliseconds field handling when using NpgsqlCopySerializer.AddDa…
…teTime() method.

Fix #221
Npgsql wasn't formatting the milliseconds field correctly when sending a DataTime to server.
Thanks @stewienj for the patch.
eb88103
@Emill Emill Rollback support for timetz in EF. It didn't work, since the TimeSpan…
… class can't handle time zones, and update and save fails (can't cast interval to timetz).

(cherry picked from commit d035d20)
dea821c
@roji roji Fixed incorrect check for .NET 2.0 f4131a6
@roji roji Added [IssueLink] for semantic markup of tests
(cherry picked from commit 7cb67b2)

Conflicts:

	tests/TestUtil.cs
754199b
@roji roji Fix rollback to savepoint when timeout is set
Fixes #363
(cherry picked from commit aa913dd)

Conflicts:

	Npgsql/Npgsql/NpgsqlTransaction.cs
	Npgsql/NpgsqlConnector.cs
6bd9062
@roji roji Fixes to ForwardsOnlyRow
Index management logic on ForwardsOnlyRow was complicated and triggered
two bugs (see tests). Redid logic in a simpler way.
(cherry picked from commit 8c996c8)

Conflicts:

	Npgsql/Npgsql/NpgsqlAsciiRow.cs
	Npgsql/Npgsql/NpgsqlRow.cs
66a83d7
@franciscojunior franciscojunior Fix handling of float and double positive infinity values.
Npgsql doesn't quote float and double values when sending to server.
But special PositiveInfinite and NegativeInfinite values need to be quoted.

Fix #337
(cherry picked from commit af88c25)
3031961
@franciscojunior franciscojunior Change code to be project style conformant.
(cherry picked from commit d54484c)
38cd018
@franciscojunior franciscojunior Improved Nan, PositiveInifinity and NegativeInfinity checking. Add
tests.

Thanks @roji for heads about about the IsNaN, IsPositiveInfinity and
IsNegativeInfinity methods.

Add tests for double and float array handing with PositiveInfinity and
NegativeInfinity.
(cherry picked from commit 0fbcf51)
fd4af98
@roji roji Tiny modifications to float text encoding
(cherry picked from commit 50126ee)
4be2ba0
@roji roji Bump version to 2.2.1 7180a97
@tompipen tompipen migration add varchar and char support
(cherry picked from commit a17854b)
a90b272
@bertl
bertl commented Oct 9, 2014

Hi, I am happy to read about this improvement. Good work!

When is it planned to merge this, since I would like to call a store procedure but I don't want that the application breaks with the next upgrade of Npgsql?

@roji roji added this to the 2.2.2 milestone Oct 9, 2014
franciscojunior and others added some commits Oct 10, 2014
@franciscojunior franciscojunior Fix NpgsqlParameter.Clone() method. It wasn't cloning the npgsqlValue…
… field.

Thanks @Tradioyes for the test and @kukhar for the patch.
Fix #371

(cherry picked from commit d67a544)
From #377
96ad7df
@franciscojunior franciscojunior Improved test to check all cloned fields. Thanks @roji for the heads up!
(cherry picked from commit d22213a)
From #377
e475170
@franciscojunior franciscojunior Fixed a problem in NpgsqlParameterCloneTest backport.
Branch 2.2 doesn't contain TypeInfo definition in NpgsqlParameter.
4ba8c5a
@Emill Emill Backport from #367.
Fixing bug in EF migration for non-fixed length string types.
(cherry picked from commit 0480702)
7589b78
@roji roji Fix prepared dispose after connection close
NpgsqlCommand now listens to its connection's open/close events.
On close, sets its prepare status to NotPrepared, avoiding the
DEALLOCATE on Dispose().

A bit of additional cleanup around command/connection relations,
but further work is needed for cases where the same command gets
transferred across connections.

Fixes #393
Relates to #299

(cherry picked from commit 5329b66)

Conflicts:
	Npgsql/NpgsqlCommand.cs
	tests/CommandTests.cs
7ab32a7
@roji
Npgsql member
roji commented Oct 23, 2014

Sorry for not being more responsive on this, there are many things happening on Npgsql at the moment. I promise to try and give this a proper look soon.

@Emill
Npgsql member
Emill commented Oct 31, 2014

I see no reasons not to merge this as soon as possible. I wonder why it has been around so long time...

Just a few things:

  • NpgsqlProviderManifest.GetDbType could probably be used instead of that large chain of if statements.
  • Check the tabs/spaces. I see both tabs and spaces in the source code.
  • What are the reason for all the if (false) {} ?
  • Since Npgsql doesn't support named parameters (yet) when dealing with stored procedures, it is important that the parameters are listed in the same order in the parameter collection as in the function definition in the database. Do you know if this is guaranteed to be true, i.e. will the xml definition list the parameters in the correct order and will EF read them in that order?
@kenjiuno

Hi @Emill

I will check my code at points from your comments.

What are the reason for all the if (false) {} ?

Sorry, it is my habit. It is more beautiful to align in case of placing the many conditions.

if (cond1) { ... }
else if (cond2) { ... }
else throw ...

if (false) { }
else if (cond1) { ... }
else if (cond2) { ... }
else throw ...

I'll check about NpgsqlProviderManifest.GetDbType.

Thanks

@roji roji modified the milestone: 2.2.3, 2.2.2 Nov 1, 2014
@roji roji modified the milestone: 2.2.3, 2.2.4 Nov 26, 2014
roji and others added some commits Nov 26, 2014
@roji roji Bump version to 2.2.4 f74e00a
@Emill Emill Backport from #461
Upgrading EF version to 6.1.2 and make Union All / Intersect compatible
f2a5938
@Emill
Npgsql member
Emill commented Jan 25, 2015

Any progress on this, @kenjiuno?

@kenjiuno

Hi.

I have once done it, but I cannot test it yet.

Plz give me some time.

@franciscojunior
Npgsql member

I just tried to push a new commit with the version 2.2.4.1.1 when git told me about your new commit. :)

Npgsql member

I thought about appending another .1 just to not it out of sync with Npgsql assembly version. But I just checked that Npgsql assembly version is 2.2.4 and not 2.2.4.1, so, the correct version for the Nuget package is really 2.2.4.2 as you did. :)

Npgsql member
roji replied Feb 5, 2015

I actually think it's a good idea for us to update the assembly info as well (which I forgot in the last bump commit, really not my week...

Npgsql member
Npgsql member
roji replied Feb 5, 2015

I have a 2.2.4.3 ready to be published, maybe it's better to just go ahead with it and this way everything is clean, probably nobody installed 2.2.4.2 (which I delisted)... any objections??

Npgsql member
@roji roji modified the milestone: 2.2.4, 2.2.5 Feb 5, 2015
roji and others added some commits Feb 5, 2015
@roji roji And one last version bump, this time with AssemblyVersion 7361b89
@franciscojunior franciscojunior Add AmazonRedshift connectionstring parameter support.
When using Npgsql with Amazon Redshift, Npgsql tries to set lc_monetary
parameter which causes problems. With this patch, if user specifies
AmazonRedshift=true in the connection string, Npgsql won't try to set
this parameter.

Thanks @mateusaubin for initial work on this issue.

Fix #476
de9e8aa
@roji roji Merge pull request #477 from franciscojunior/476-workaround-lcmonetar…
…y-redshift-support

Add AmazonRedshift connectionstring parameter support.
d183956
@roji roji Fixed bad quoting/unquoting in CommandBuilder
Thanks @Brar for raising and fixing

(cherry picked from commit a81a820)
a54809b
@franciscojunior franciscojunior Revert "Add AmazonRedshift connectionstring parameter support." d4d9a51
@franciscojunior franciscojunior Merge pull request #490 from npgsql/revert-477-476-workaround-lcmonet…
…ary-redshift-support

Revert "Add AmazonRedshift connectionstring parameter support."
9cccf25
@franciscojunior franciscojunior Add check for lc_monetary parameter support.
Only servers 8.1 and above will have the lc_monetary parameter set.
This will fix Amazon Redshift errors when connecting.

Fix #476
beab95d
@franciscojunior franciscojunior Remove StartupPacket lc_monetary parameter.
It is now set dinamically based on server version.
786ef9c
@franciscojunior franciscojunior Merge pull request #489 from franciscojunior/476-workaround-lcmonetar…
…y-redshift-support-3

Add check for lc_monetary parameter support.
f3d626a
@havard havard Leak removal: Set BaseStream to null when closing connections. aeba02a
@roji roji Command no longer subscribes to connection's state event
NpgsqlCommand was listening to its connection's StateChange event so as
to know when the latter was closed, in order to clear its prepared status.
However, it seems that Entity Framework does not dispose of commands, which
led to a leak (since commands never get unsubscribed from their connections).

Rewrote the mechanism without events: a connection maintains a counter that
gets incremented on each open, and the command knows for which counter (i.e.
connection instance) it was prepared.

Backport of 31bdcce

Fixes #505
257094f
@roji roji Bump version to 2.2.5 1d31a35
@roji roji modified the milestone: 2.2.5 Mar 2, 2015
roji and others added some commits Mar 2, 2015
@roji roji Merge pull request #510 from havard/2.2
Leak removal: Set BaseStream to null when closing connections.
124adeb
@roji roji Changed maintenance DB from postgres to template1
EntityFramework needs a "maintenance" DB in order to create databases,
etc. Previously this was "postgres", but that is available only starting
from PostgreSQL version 8.1. Redshift is based off 8.0 and so EF broke
on it.

Changed to use "template1" instead, which exists on all PostgreSQL versions.

Fixes #511

(cherry picked from commit 721d5b5)
7e26f33
@roji roji Correctly parse scientific notation for geometric types
Fixes #514
0098911
@roji roji Work on unit test init, Redshift & performance
* Unify test setup to single multi-query SQL, faster test startup
* Unit tests now initialize properly on Redshift (different PK creation,
  don't create unsupported data types). Many unit tests will still break
  on Redshift, need to flag them for ignore.
0606e5e
@Emill Emill Add support for string literals in EF for backends < 8.1 93266fd
Shay Rojansky Tweak to compile 93266fd pre-NET40 a4522cc
@roji roji Upgrade to EntityFramework 6.1.3 e789427
@roji roji Upgrade to NUnit 2.6.4 4765b11
@roji roji Bump version to 2.2.6 1f8d0e5
@roji roji No longer open separate conn in GetSchema()
NpgsqlConnection.GetSchema() used to open a new temporary connection,
modified to reuse the existing connection.

Fixes #543

(cherry picked from commit 68926d8)

Conflicts:
	tests/ConnectionTests.cs
85736b0
@jacobovazquez jacobovazquez Added krbsrvname parameter and use hostname for SSPI authentication
The GSS and SSPI authentication needs the kerberos service name of the
PostgreSQL server. The default value is POSTGRES but this value can be
changed. The ODBC driver allows to set this value using the
configuration option "krbsrvname". This patch allows to send this
parameter in the connection string.

If the ip address is used instead of the hostname, the SSPI
authentication process uses NTLM authentication. By using the host name
it tries first to use Kerberos and if this is not possible NTLM is used.
7e2d240
@jacobovazquez jacobovazquez Added krbsrvname parameter and use hostname for SSPI authentication
The GSS and SSPI authentication needs the kerberos service name of the
PostgreSQL server. The default value is POSTGRES but this value can be
changed. The ODBC driver allows to set this value using the
configuration option "krbsrvname". This patch allows to send this
parameter in the connection string.

If the ip address is used instead of the hostname, the SSPI
authentication process uses NTLM authentication. By using the host name
it tries first to use Kerberos and if this is not possible NTLM is used.
cfaa52b
@jacobovazquez jacobovazquez Added krbsrvname values to resource file
Added values for ConnectionProperty_Description_Krbsrvname and
ConnectionProperty_Display_Krbsrvname to the resource file
0492b34
@havard havard Guard against connector being null (race condition) ff6d23f
@roji roji Merge pull request #572 from jacobovazquez/2.2
Added krbsrvname parameter and use hostname for SSPI authentication to 2.2
a0399f6
@roji roji Merge pull request #573 from havard/2.2
Fix NullReferenceException when disposing transactions (race conditon (?))
9bbb1f2
@kenjiuno kenjiuno Add initial support for ObjectContext.ExecuteFunction 8b701a4
@kenjiuno kenjiuno Adding 2 tests for ObjectContext.ExecuteFunction 47174a7
@kenjiuno kenjiuno Untested. 3617850
@kenjiuno kenjiuno Testings. 2bd5ff7
@kenjiuno

Sorry, my branch is broken now. I'll setup new pr against 2.2

@kenjiuno kenjiuno closed this Apr 25, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.