diff --git a/.gitignore b/.gitignore index adc05e9..f10af03 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ *.sln.docstates *.userprefs /*.nupkg +.idea/ .nuget/ [Bb]in/ [Bb]uild/ diff --git a/.teamcity/EntityFramework6Npgsql/buildTypes/EntityFramework6Npgsql_Build.xml b/.teamcity/EntityFramework6Npgsql/buildTypes/EntityFramework6Npgsql_Build.xml deleted file mode 100644 index 3ae11b0..0000000 --- a/.teamcity/EntityFramework6Npgsql/buildTypes/EntityFramework6Npgsql_Build.xml +++ /dev/null @@ -1,137 +0,0 @@ - - - Build - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/.teamcity/EntityFramework6Npgsql/pluginData/plugin-settings.xml b/.teamcity/EntityFramework6Npgsql/pluginData/plugin-settings.xml deleted file mode 100644 index 784b770..0000000 --- a/.teamcity/EntityFramework6Npgsql/pluginData/plugin-settings.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/.teamcity/EntityFramework6Npgsql/project-config.xml b/.teamcity/EntityFramework6Npgsql/project-config.xml deleted file mode 100644 index 6c2ccfb..0000000 --- a/.teamcity/EntityFramework6Npgsql/project-config.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - EntityFramework6.Npgsql - Entity Framework 6/5 for PostgreSQL - - - - - - diff --git a/.teamcity/EntityFramework6Npgsql/vcsRoots/EntityFramework6Npgsql_Github.xml b/.teamcity/EntityFramework6Npgsql/vcsRoots/EntityFramework6Npgsql_Github.xml deleted file mode 100644 index 7c55983..0000000 --- a/.teamcity/EntityFramework6Npgsql/vcsRoots/EntityFramework6Npgsql_Github.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - https://github.com/npgsql/EntityFramework6.Npgsql.git - - - - - - - - - - - - - - diff --git a/Directory.Build.props b/Directory.Build.props new file mode 100644 index 0000000..3c65479 --- /dev/null +++ b/Directory.Build.props @@ -0,0 +1,14 @@ + + + + true + snupkg + + + + + + + + diff --git a/Directory.Build.targets b/Directory.Build.targets new file mode 100644 index 0000000..d3fa71d --- /dev/null +++ b/Directory.Build.targets @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/EntityFramework6.Npgsql.Tests/App.config b/EF6.PG.Tests/App.config similarity index 95% rename from test/EntityFramework6.Npgsql.Tests/App.config rename to EF6.PG.Tests/App.config index 931aca8..f113db7 100644 --- a/test/EntityFramework6.Npgsql.Tests/App.config +++ b/EF6.PG.Tests/App.config @@ -29,7 +29,7 @@ - + diff --git a/EF6.PG.Tests/EF6.PG.Tests.csproj b/EF6.PG.Tests/EF6.PG.Tests.csproj new file mode 100644 index 0000000..5f9b005 --- /dev/null +++ b/EF6.PG.Tests/EF6.PG.Tests.csproj @@ -0,0 +1,19 @@ + + + latest + net45;netcoreapp3.1 + EntityFramework6.Npgsql.Tests + EntityFramework6.Npgsql.Tests + + + + + + + + + + + + + diff --git a/test/EntityFramework6.Npgsql.Tests/EntityFrameworkBasicTests.cs b/EF6.PG.Tests/EntityFrameworkBasicTests.cs similarity index 91% rename from test/EntityFramework6.Npgsql.Tests/EntityFrameworkBasicTests.cs rename to EF6.PG.Tests/EntityFrameworkBasicTests.cs index cc7d85f..cb52e3d 100644 --- a/test/EntityFramework6.Npgsql.Tests/EntityFrameworkBasicTests.cs +++ b/EF6.PG.Tests/EntityFrameworkBasicTests.cs @@ -1,27 +1,4 @@ -#region License -// The PostgreSQL License -// -// Copyright (C) 2016 The Npgsql Development Team -// -// Permission to use, copy, modify, and distribute this software and its -// documentation for any purpose, without fee, and without a written -// agreement is hereby granted, provided that the above copyright notice -// and this paragraph and the following two paragraphs appear in all copies. -// -// IN NO EVENT SHALL THE NPGSQL DEVELOPMENT TEAM BE LIABLE TO ANY PARTY -// FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, -// INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS -// DOCUMENTATION, EVEN IF THE NPGSQL DEVELOPMENT TEAM HAS BEEN ADVISED OF -// THE POSSIBILITY OF SUCH DAMAGE. -// -// THE NPGSQL DEVELOPMENT TEAM SPECIFICALLY DISCLAIMS ANY WARRANTIES, -// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY -// AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS -// ON AN "AS IS" BASIS, AND THE NPGSQL DEVELOPMENT TEAM HAS NO OBLIGATIONS -// TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. -#endregion - -using Npgsql; +using Npgsql; using NUnit.Framework; using System; using System.Collections.Generic; @@ -847,5 +824,95 @@ public void Test_string_multiple_null_propagation() query.ToString()); } } + + [Test] + public void Test_enum() + { + using (var context = new BloggingContext(ConnectionString)) + { + context.Database.Log = Console.Out.WriteLine; + + context.ClrEnumEntities.Add( + new ClrEnumEntity + { + TestByte = TestByteEnum.Bar, + TestShort = TestShortEnum.Bar, + TestInt = TestIntEnum.Bar, + TestLong = TestLongEnum.Bar + }); + context.SaveChanges(); + + var query = context.ClrEnumEntities.Where( + x => x.TestByte == TestByteEnum.Bar + && x.TestShort == TestShortEnum.Bar + && x.TestInt == TestIntEnum.Bar + && x.TestLong == TestLongEnum.Bar); + + var result = query.First(); + Assert.That(result.TestByte, Is.EqualTo(TestByteEnum.Bar)); + Assert.That(result.TestShort, Is.EqualTo(TestShortEnum.Bar)); + Assert.That(result.TestInt, Is.EqualTo(TestIntEnum.Bar)); + Assert.That(result.TestLong, Is.EqualTo(TestLongEnum.Bar)); + } + } + + [Test] + public void Test_enum_composite_key() + { + using (var context = new BloggingContext(ConnectionString)) + { + context.Database.Log = Console.Out.WriteLine; + + context.ClrEnumCompositeKeyEntities.Add( + new ClrEnumCompositeKeyEntity + { + TestByte = TestByteEnum.Bar, + TestShort = TestShortEnum.Bar, + TestInt = TestIntEnum.Bar, + TestLong = TestLongEnum.Bar + }); + context.SaveChanges(); + } + + using (var context = new BloggingContext(ConnectionString)) + { + var result = context.ClrEnumCompositeKeyEntities.Find( + TestByteEnum.Bar, + TestShortEnum.Bar, + TestIntEnum.Bar, + TestLongEnum.Bar); + + Assert.That(result, Is.Not.Null); + Assert.That(result.TestByte, Is.EqualTo(TestByteEnum.Bar)); + Assert.That(result.TestShort, Is.EqualTo(TestShortEnum.Bar)); + Assert.That(result.TestInt, Is.EqualTo(TestIntEnum.Bar)); + Assert.That(result.TestLong, Is.EqualTo(TestLongEnum.Bar)); + } + } + + [Test] + public void Test_non_composable_function() + { + using (var context = new BloggingContext(ConnectionString)) + { + context.Database.Log = Console.Out.WriteLine; + + // Add some data and query it back using Stored Function + context.Blogs.Add(new Blog + { + Name = "Some blog1 name", + Posts = new List() + }); + context.SaveChanges(); + + // Query back + var nameParameter = new ObjectParameter("Name", "blog1"); + var blogs = ((IObjectContextAdapter)context).ObjectContext.ExecuteFunction("GetBlogsByName2", nameParameter).ToArray(); + + Assert.AreEqual(1, blogs.Length); + Assert.AreEqual("Some blog1 name", blogs[0].Name); + } + } + } } diff --git a/test/EntityFramework6.Npgsql.Tests/EntityFrameworkMigrationTests.cs b/EF6.PG.Tests/EntityFrameworkMigrationTests.cs similarity index 97% rename from test/EntityFramework6.Npgsql.Tests/EntityFrameworkMigrationTests.cs rename to EF6.PG.Tests/EntityFrameworkMigrationTests.cs index dccc6fd..3fde9fb 100644 --- a/test/EntityFramework6.Npgsql.Tests/EntityFrameworkMigrationTests.cs +++ b/EF6.PG.Tests/EntityFrameworkMigrationTests.cs @@ -1,27 +1,4 @@ -#region License -// The PostgreSQL License -// -// Copyright (C) 2016 The Npgsql Development Team -// -// Permission to use, copy, modify, and distribute this software and its -// documentation for any purpose, without fee, and without a written -// agreement is hereby granted, provided that the above copyright notice -// and this paragraph and the following two paragraphs appear in all copies. -// -// IN NO EVENT SHALL THE NPGSQL DEVELOPMENT TEAM BE LIABLE TO ANY PARTY -// FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, -// INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS -// DOCUMENTATION, EVEN IF THE NPGSQL DEVELOPMENT TEAM HAS BEEN ADVISED OF -// THE POSSIBILITY OF SUCH DAMAGE. -// -// THE NPGSQL DEVELOPMENT TEAM SPECIFICALLY DISCLAIMS ANY WARRANTIES, -// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY -// AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS -// ON AN "AS IS" BASIS, AND THE NPGSQL DEVELOPMENT TEAM HAS NO OBLIGATIONS -// TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. -#endregion - -using Npgsql; +using Npgsql; using NUnit.Framework; using System; using System.Collections.Generic; @@ -491,7 +468,7 @@ public void RenameIndexOperation() } else { - Assert.AreEqual("ALTER INDEX someSchema.\"someOldIndexName\" RENAME TO \"someNewIndexName\"", statements.ElementAt(0).Sql); + Assert.AreEqual("ALTER INDEX someSchema.\"someOldIndexName\" RENAME TO \"someNewIndexName\"", statements.ElementAt(0).Sql); } } diff --git a/test/EntityFramework6.Npgsql.Tests/FullTextSearchTests.cs b/EF6.PG.Tests/FullTextSearchTests.cs similarity index 95% rename from test/EntityFramework6.Npgsql.Tests/FullTextSearchTests.cs rename to EF6.PG.Tests/FullTextSearchTests.cs index 101e8b3..6d81f43 100644 --- a/test/EntityFramework6.Npgsql.Tests/FullTextSearchTests.cs +++ b/EF6.PG.Tests/FullTextSearchTests.cs @@ -1,27 +1,4 @@ -#region License -// The PostgreSQL License -// -// Copyright (C) 2016 The Npgsql Development Team -// -// Permission to use, copy, modify, and distribute this software and its -// documentation for any purpose, without fee, and without a written -// agreement is hereby granted, provided that the above copyright notice -// and this paragraph and the following two paragraphs appear in all copies. -// -// IN NO EVENT SHALL THE NPGSQL DEVELOPMENT TEAM BE LIABLE TO ANY PARTY -// FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, -// INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS -// DOCUMENTATION, EVEN IF THE NPGSQL DEVELOPMENT TEAM HAS BEEN ADVISED OF -// THE POSSIBILITY OF SUCH DAMAGE. -// -// THE NPGSQL DEVELOPMENT TEAM SPECIFICALLY DISCLAIMS ANY WARRANTIES, -// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY -// AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS -// ON AN "AS IS" BASIS, AND THE NPGSQL DEVELOPMENT TEAM HAS NO OBLIGATIONS -// TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. -#endregion - -using Npgsql; +using Npgsql; using NUnit.Framework; using System; using System.Collections.Generic; diff --git a/test/EntityFramework6.Npgsql.Tests/NLogLoggingProvider.cs b/EF6.PG.Tests/NLogLoggingProvider.cs similarity index 59% rename from test/EntityFramework6.Npgsql.Tests/NLogLoggingProvider.cs rename to EF6.PG.Tests/NLogLoggingProvider.cs index e8940e9..509a7f3 100644 --- a/test/EntityFramework6.Npgsql.Tests/NLogLoggingProvider.cs +++ b/EF6.PG.Tests/NLogLoggingProvider.cs @@ -1,27 +1,4 @@ -#region License -// The PostgreSQL License -// -// Copyright (C) 2016 The Npgsql Development Team -// -// Permission to use, copy, modify, and distribute this software and its -// documentation for any purpose, without fee, and without a written -// agreement is hereby granted, provided that the above copyright notice -// and this paragraph and the following two paragraphs appear in all copies. -// -// IN NO EVENT SHALL THE NPGSQL DEVELOPMENT TEAM BE LIABLE TO ANY PARTY -// FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, -// INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS -// DOCUMENTATION, EVEN IF THE NPGSQL DEVELOPMENT TEAM HAS BEEN ADVISED OF -// THE POSSIBILITY OF SUCH DAMAGE. -// -// THE NPGSQL DEVELOPMENT TEAM SPECIFICALLY DISCLAIMS ANY WARRANTIES, -// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY -// AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS -// ON AN "AS IS" BASIS, AND THE NPGSQL DEVELOPMENT TEAM HAS NO OBLIGATIONS -// TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. -#endregion - -using System; +using System; using NLog; using Npgsql.Logging; diff --git a/test/EntityFramework6.Npgsql.Tests/PatternMatchingTests.cs b/EF6.PG.Tests/PatternMatchingTests.cs similarity index 85% rename from test/EntityFramework6.Npgsql.Tests/PatternMatchingTests.cs rename to EF6.PG.Tests/PatternMatchingTests.cs index 6260b90..6f83d75 100644 --- a/test/EntityFramework6.Npgsql.Tests/PatternMatchingTests.cs +++ b/EF6.PG.Tests/PatternMatchingTests.cs @@ -1,27 +1,4 @@ -#region License -// The PostgreSQL License -// -// Copyright (C) 2016 The Npgsql Development Team -// -// Permission to use, copy, modify, and distribute this software and its -// documentation for any purpose, without fee, and without a written -// agreement is hereby granted, provided that the above copyright notice -// and this paragraph and the following two paragraphs appear in all copies. -// -// IN NO EVENT SHALL THE NPGSQL DEVELOPMENT TEAM BE LIABLE TO ANY PARTY -// FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, -// INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS -// DOCUMENTATION, EVEN IF THE NPGSQL DEVELOPMENT TEAM HAS BEEN ADVISED OF -// THE POSSIBILITY OF SUCH DAMAGE. -// -// THE NPGSQL DEVELOPMENT TEAM SPECIFICALLY DISCLAIMS ANY WARRANTIES, -// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY -// AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS -// ON AN "AS IS" BASIS, AND THE NPGSQL DEVELOPMENT TEAM HAS NO OBLIGATIONS -// TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. -#endregion - -using Npgsql; +using Npgsql; using NUnit.Framework; using System; using System.Collections.Generic; diff --git a/test/EntityFramework6.Npgsql.Tests/Spatial/PostgisServiceTests.cs b/EF6.PG.Tests/Spatial/PostgisServiceTests.cs similarity index 100% rename from test/EntityFramework6.Npgsql.Tests/Spatial/PostgisServiceTests.cs rename to EF6.PG.Tests/Spatial/PostgisServiceTests.cs diff --git a/EF6.PG.Tests/Support/AssemblySetup.cs b/EF6.PG.Tests/Support/AssemblySetup.cs new file mode 100644 index 0000000..e503497 --- /dev/null +++ b/EF6.PG.Tests/Support/AssemblySetup.cs @@ -0,0 +1,30 @@ +using System.Data.Entity; +using NLog.Config; +using NLog.Targets; +using NUnit.Framework; +using Npgsql.Logging; +using EntityFramework6.Npgsql.Tests; +using EntityFramework6.Npgsql.Tests.Support; + +// ReSharper disable CheckNamespace + +[SetUpFixture] +public class AssemblySetup +{ + [OneTimeSetUp] + public void RegisterDbProvider() + { + var config = new LoggingConfiguration(); + var consoleTarget = new ConsoleTarget(); + consoleTarget.Layout = @"${message} ${exception:format=tostring}"; + config.AddTarget("console", consoleTarget); + var rule = new LoggingRule("*", NLog.LogLevel.Info, consoleTarget); + config.LoggingRules.Add(rule); + NLog.LogManager.Configuration = config; + + NpgsqlLogManager.Provider = new NLogLoggingProvider(); + NpgsqlLogManager.IsParameterLoggingEnabled = true; + + DbConfiguration.SetConfiguration(new TestDbConfiguration()); + } +} diff --git a/test/EntityFramework6.Npgsql.Tests/Support/CodeAnnotations.cs b/EF6.PG.Tests/Support/CodeAnnotations.cs similarity index 100% rename from test/EntityFramework6.Npgsql.Tests/Support/CodeAnnotations.cs rename to EF6.PG.Tests/Support/CodeAnnotations.cs diff --git a/test/EntityFramework6.Npgsql.Tests/Support/EntityFrameworkTestBase.cs b/EF6.PG.Tests/Support/EntityFrameworkTestBase.cs similarity index 73% rename from test/EntityFramework6.Npgsql.Tests/Support/EntityFrameworkTestBase.cs rename to EF6.PG.Tests/Support/EntityFrameworkTestBase.cs index d00f6ca..5504281 100644 --- a/test/EntityFramework6.Npgsql.Tests/Support/EntityFrameworkTestBase.cs +++ b/EF6.PG.Tests/Support/EntityFrameworkTestBase.cs @@ -1,30 +1,8 @@ -#region License -// The PostgreSQL License -// -// Copyright (C) 2016 The Npgsql Development Team -// -// Permission to use, copy, modify, and distribute this software and its -// documentation for any purpose, without fee, and without a written -// agreement is hereby granted, provided that the above copyright notice -// and this paragraph and the following two paragraphs appear in all copies. -// -// IN NO EVENT SHALL THE NPGSQL DEVELOPMENT TEAM BE LIABLE TO ANY PARTY -// FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, -// INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS -// DOCUMENTATION, EVEN IF THE NPGSQL DEVELOPMENT TEAM HAS BEEN ADVISED OF -// THE POSSIBILITY OF SUCH DAMAGE. -// -// THE NPGSQL DEVELOPMENT TEAM SPECIFICALLY DISCLAIMS ANY WARRANTIES, -// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY -// AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS -// ON AN "AS IS" BASIS, AND THE NPGSQL DEVELOPMENT TEAM HAS NO OBLIGATIONS -// TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. -#endregion - -using Npgsql; +using Npgsql; using NUnit.Framework; using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.Data.Common; using System.Data.Entity; using System.Linq; @@ -60,6 +38,7 @@ public abstract class EntityFrameworkTestBase : TestBase createSequenceConn.ExecuteNonQuery("CREATE OR REPLACE FUNCTION \"dbo\".\"StoredAddFunction\"(integer, integer) RETURNS integer AS $$ SELECT $1 + $2; $$ LANGUAGE SQL;"); createSequenceConn.ExecuteNonQuery("CREATE OR REPLACE FUNCTION \"dbo\".\"StoredEchoFunction\"(integer) RETURNS integer AS $$ SELECT $1; $$ LANGUAGE SQL;"); createSequenceConn.ExecuteNonQuery("CREATE OR REPLACE FUNCTION \"dbo\".\"GetBlogsByName\"(text) RETURNS TABLE(\"BlogId\" int, \"Name\" text, \"IntComputedValue\" int) as $$ select \"BlogId\", \"Name\", \"IntComputedValue\" from \"dbo\".\"Blogs\" where \"Name\" ilike '%' || $1 || '%' $$ LANGUAGE SQL;"); + createSequenceConn.ExecuteNonQuery("CREATE OR REPLACE FUNCTION \"dbo\".\"GetBlogsByName2\"(text) RETURNS TABLE(\"BlogId\" int, \"Name\" text, \"IntComputedValue\" int) as $$ select \"BlogId\", \"Name\", \"IntComputedValue\" from \"dbo\".\"Blogs\" where \"Name\" ilike '%' || $1 || '%' $$ LANGUAGE SQL;"); } } @@ -102,6 +81,54 @@ public class Post public virtual Blog Blog { get; set; } } + public class ClrEnumEntity + { + public int Id { get; set; } + public TestByteEnum TestByte { get; set; } + public TestShortEnum TestShort { get; set; } + public TestIntEnum TestInt { get; set; } + public TestLongEnum TestLong { get; set; } + } + + public class ClrEnumCompositeKeyEntity + { + [Key, Column(Order = 1)] + public TestByteEnum TestByte { get; set; } + + [Key, Column(Order = 2)] + public TestShortEnum TestShort { get; set; } + + [Key, Column(Order = 3)] + public TestIntEnum TestInt { get; set; } + + [Key, Column(Order = 4)] + public TestLongEnum TestLong { get; set; } + } + + public enum TestByteEnum : byte + { + Foo = 0, + Bar = 1 + } + + public enum TestShortEnum : short + { + Foo = 0, + Bar = 1 + } + + public enum TestIntEnum + { + Foo = 0, + Bar = 1 + } + + public enum TestLongEnum : long + { + Foo = 0, + Bar = 1 + } + public class NoColumnsEntity { public int Id { get; set; } @@ -131,6 +158,8 @@ public BloggingContext(string connection) public DbSet Blogs { get; set; } public DbSet Posts { get; set; } public DbSet NoColumnsEntities { get; set; } + public DbSet ClrEnumEntities { get; set; } + public DbSet ClrEnumCompositeKeyEntities { get; set; } public DbSet Users { get; set; } public DbSet Editors { get; set; } public DbSet Administrators { get; set; } @@ -151,7 +180,7 @@ public static int StoredEchoFunction(int value) public IQueryable GetBlogsByName(string name) { ObjectParameter nameParameter = new ObjectParameter("Name", name); - + return ((IObjectContextAdapter)this).ObjectContext.CreateQuery( $"[GetBlogsByName](@Name)", nameParameter); } @@ -164,6 +193,8 @@ private static DbCompiledModel CreateModel(NpgsqlConnection connection) dbModelBuilder.Entity(); dbModelBuilder.Entity(); dbModelBuilder.Entity(); + dbModelBuilder.Entity(); + dbModelBuilder.Entity(); dbModelBuilder.Entity(); dbModelBuilder.Entity(); dbModelBuilder.Entity(); @@ -284,7 +315,7 @@ private static DbCompiledModel CreateModel(NpgsqlConnection connection) { IsFunctionImport = true, IsComposable = true, - Parameters = new[] + Parameters = new[] { FunctionParameter.Create("Name", stringPrimitiveType, ParameterMode.In) }, @@ -292,7 +323,7 @@ private static DbCompiledModel CreateModel(NpgsqlConnection connection) { FunctionParameter.Create("ReturnType1", modelBlogConceptualType.GetCollectionType(), ParameterMode.ReturnValue) }, - EntitySets = new[] + EntitySets = new[] { dbModel.ConceptualModel.Container.EntitySets.First(x => x.ElementType == modelBlogConceptualType) } @@ -306,8 +337,71 @@ private static DbCompiledModel CreateModel(NpgsqlConnection connection) new FunctionImportResultMapping(), dbModel.ConceptualToStoreMapping)); + + var getBlogs2Func = EdmFunction.Create( + "GetBlogsByName2", + "BloggingContext", + DataSpace.SSpace, + new EdmFunctionPayload + { + ParameterTypeSemantics = ParameterTypeSemantics.AllowImplicitConversion, + Schema = "dbo", + IsComposable = false, + IsNiladic = false, + IsBuiltIn = false, + IsAggregate = false, + StoreFunctionName = "GetBlogsByName2", + ReturnParameters = new[] + { + FunctionParameter.Create("ReturnType1", rowType.GetCollectionType(), ParameterMode.ReturnValue) + }, + Parameters = new[] + { + FunctionParameter.Create("Name", stringStoreType, ParameterMode.In) + } + }, + null); + dbModel.StoreModel.AddItem(getBlogs2Func); + + EdmFunction getBlogs2FuncModel = EdmFunction.Create( + "GetBlogsByName2", + dbModel.ConceptualModel.Container.Name, + DataSpace.CSpace, + new EdmFunctionPayload + { + IsFunctionImport = true, + IsComposable = false, + Parameters = new[] + { + FunctionParameter.Create("Name", stringPrimitiveType, ParameterMode.In) + }, + ReturnParameters = new[] + { + FunctionParameter.Create("ReturnType1", modelBlogConceptualType.GetCollectionType(), ParameterMode.ReturnValue) + }, + EntitySets = new[] + { + dbModel.ConceptualModel.Container.EntitySets.First(x => x.ElementType == modelBlogConceptualType) + } + }, + null); + dbModel.ConceptualModel.Container.AddFunctionImport(getBlogs2FuncModel); + + dbModel.ConceptualToStoreMapping.AddFunctionImportMapping(new FunctionImportMappingNonComposable( + getBlogs2FuncModel, + getBlogs2Func, + new FunctionImportResultMapping[] { }, + dbModel.ConceptualToStoreMapping)); + + var compiledModel = dbModel.Compile(); return compiledModel; } + + protected override void OnModelCreating(DbModelBuilder modelBuilder) + { + //modelBuilder.Conventions.Add(new FunctionsConvention("dbo")); + base.OnModelCreating(modelBuilder); + } } } diff --git a/test/EntityFramework6.Npgsql.Tests/Support/TestBase.cs b/EF6.PG.Tests/Support/TestBase.cs similarity index 55% rename from test/EntityFramework6.Npgsql.Tests/Support/TestBase.cs rename to EF6.PG.Tests/Support/TestBase.cs index d11f508..cf23265 100644 --- a/test/EntityFramework6.Npgsql.Tests/Support/TestBase.cs +++ b/EF6.PG.Tests/Support/TestBase.cs @@ -1,27 +1,4 @@ -#region License -// The PostgreSQL License -// -// Copyright (C) 2016 The Npgsql Development Team -// -// Permission to use, copy, modify, and distribute this software and its -// documentation for any purpose, without fee, and without a written -// agreement is hereby granted, provided that the above copyright notice -// and this paragraph and the following two paragraphs appear in all copies. -// -// IN NO EVENT SHALL THE NPGSQL DEVELOPMENT TEAM BE LIABLE TO ANY PARTY -// FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, -// INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS -// DOCUMENTATION, EVEN IF THE NPGSQL DEVELOPMENT TEAM HAS BEEN ADVISED OF -// THE POSSIBILITY OF SUCH DAMAGE. -// -// THE NPGSQL DEVELOPMENT TEAM SPECIFICALLY DISCLAIMS ANY WARRANTIES, -// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY -// AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS -// ON AN "AS IS" BASIS, AND THE NPGSQL DEVELOPMENT TEAM HAS NO OBLIGATIONS -// TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. -#endregion - -using System; +using System; using NLog.Config; using NLog.Targets; using NLog; @@ -46,8 +23,6 @@ public abstract class TestBase string _connectionString; - static bool _loggingSetUp; - /// /// Unless the NPGSQL_TEST_DB environment variable is defined, this is used as the connection string for the /// test database. @@ -59,28 +34,9 @@ public abstract class TestBase [OneTimeSetUp] public virtual void TestFixtureSetup() { - SetupLogging(); _log.Debug("Connection string is: " + ConnectionString); } - protected virtual void SetupLogging() - { - var config = new LoggingConfiguration(); - var consoleTarget = new ConsoleTarget(); - consoleTarget.Layout = @"${message} ${exception:format=tostring}"; - config.AddTarget("console", consoleTarget); - var rule = new LoggingRule("*", NLog.LogLevel.Debug, consoleTarget); - config.LoggingRules.Add(rule); - NLog.LogManager.Configuration = config; - - if (!_loggingSetUp) - { - NpgsqlLogManager.Provider = new NLogLoggingProvider(); - NpgsqlLogManager.IsParameterLoggingEnabled = true; - _loggingSetUp = true; - } - } - #endregion #region Utilities for use by tests diff --git a/EF6.PG.Tests/Support/TestDbConfiguration.cs b/EF6.PG.Tests/Support/TestDbConfiguration.cs new file mode 100644 index 0000000..2276bed --- /dev/null +++ b/EF6.PG.Tests/Support/TestDbConfiguration.cs @@ -0,0 +1,15 @@ +using System; +using System.Data.Entity; +using Npgsql; + +namespace EntityFramework6.Npgsql.Tests.Support +{ + public class TestDbConfiguration : DbConfiguration + { + public TestDbConfiguration() + { + SetProviderFactory("Npgsql", NpgsqlFactory.Instance); + SetProviderServices("Npgsql", NpgsqlServices.Instance); + } + } +} diff --git a/test/EntityFramework6.Npgsql.Tests/Support/TestUtil.cs b/EF6.PG.Tests/Support/TestUtil.cs similarity index 79% rename from test/EntityFramework6.Npgsql.Tests/Support/TestUtil.cs rename to EF6.PG.Tests/Support/TestUtil.cs index b34eeab..5b46519 100644 --- a/test/EntityFramework6.Npgsql.Tests/Support/TestUtil.cs +++ b/EF6.PG.Tests/Support/TestUtil.cs @@ -1,27 +1,4 @@ -#region License -// The PostgreSQL License -// -// Copyright (C) 2016 The Npgsql Development Team -// -// Permission to use, copy, modify, and distribute this software and its -// documentation for any purpose, without fee, and without a written -// agreement is hereby granted, provided that the above copyright notice -// and this paragraph and the following two paragraphs appear in all copies. -// -// IN NO EVENT SHALL THE NPGSQL DEVELOPMENT TEAM BE LIABLE TO ANY PARTY -// FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, -// INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS -// DOCUMENTATION, EVEN IF THE NPGSQL DEVELOPMENT TEAM HAS BEEN ADVISED OF -// THE POSSIBILITY OF SUCH DAMAGE. -// -// THE NPGSQL DEVELOPMENT TEAM SPECIFICALLY DISCLAIMS ANY WARRANTIES, -// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY -// AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS -// ON AN "AS IS" BASIS, AND THE NPGSQL DEVELOPMENT TEAM HAS NO OBLIGATIONS -// TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. -#endregion - -using System; +using System; using System.Threading; using System.Threading.Tasks; using JetBrains.Annotations; diff --git a/test/EntityFramework6.Npgsql.Tests/xmlModel/XmlTest.ObjectLayer.EF6.cs b/EF6.PG.Tests/xmlModel/XmlTest.ObjectLayer.EF6.cs similarity index 100% rename from test/EntityFramework6.Npgsql.Tests/xmlModel/XmlTest.ObjectLayer.EF6.cs rename to EF6.PG.Tests/xmlModel/XmlTest.ObjectLayer.EF6.cs diff --git a/test/EntityFramework6.Npgsql.Tests/xmlModel/XmlTest.ObjectLayer.cs b/EF6.PG.Tests/xmlModel/XmlTest.ObjectLayer.cs similarity index 100% rename from test/EntityFramework6.Npgsql.Tests/xmlModel/XmlTest.ObjectLayer.cs rename to EF6.PG.Tests/xmlModel/XmlTest.ObjectLayer.cs diff --git a/test/EntityFramework6.Npgsql.Tests/xmlModel/XmlTest.csdl b/EF6.PG.Tests/xmlModel/XmlTest.csdl similarity index 100% rename from test/EntityFramework6.Npgsql.Tests/xmlModel/XmlTest.csdl rename to EF6.PG.Tests/xmlModel/XmlTest.csdl diff --git a/test/EntityFramework6.Npgsql.Tests/xmlModel/XmlTest.msl b/EF6.PG.Tests/xmlModel/XmlTest.msl similarity index 100% rename from test/EntityFramework6.Npgsql.Tests/xmlModel/XmlTest.msl rename to EF6.PG.Tests/xmlModel/XmlTest.msl diff --git a/test/EntityFramework6.Npgsql.Tests/xmlModel/XmlTest.ssdl b/EF6.PG.Tests/xmlModel/XmlTest.ssdl similarity index 100% rename from test/EntityFramework6.Npgsql.Tests/xmlModel/XmlTest.ssdl rename to EF6.PG.Tests/xmlModel/XmlTest.ssdl diff --git a/src/EntityFramework6.Npgsql/App.config b/EF6.PG/App.config similarity index 100% rename from src/EntityFramework6.Npgsql/App.config rename to EF6.PG/App.config diff --git a/EF6.PG/EF6.PG.csproj b/EF6.PG/EF6.PG.csproj new file mode 100644 index 0000000..b84b9bc --- /dev/null +++ b/EF6.PG/EF6.PG.csproj @@ -0,0 +1,56 @@ + + + PostgreSQL provider for Entity Framework 6 + Shay Rojansky;Emil Lenngren;Francisco Figueiredo Jr.;Kenji Uno + Copyright 2020 © The Npgsql Development Team + Npgsql + npgsql postgresql postgres data database entity framework ef orm + 6.4.3 + latest + net45;net461;netstandard21 + true + CS1591 + true + Npgsql + EntityFramework6.Npgsql + true + ../Npgsql.snk + true + true + https://github.com/npgsql/EntityFramework6.Npgsql + postgresql.png + PostgreSQL + git + git://github.com/npgsql/EntityFramework6.Npgsql + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/EF6.PG/NpgsqlConnectionFactory.cs b/EF6.PG/NpgsqlConnectionFactory.cs new file mode 100644 index 0000000..1d5e499 --- /dev/null +++ b/EF6.PG/NpgsqlConnectionFactory.cs @@ -0,0 +1,21 @@ +using System.Data.Common; +using System.Data.Entity.Infrastructure; + +namespace Npgsql +{ + /// + /// Instances of this class are used to create DbConnection objects for Postgresql + /// + public class NpgsqlConnectionFactory : IDbConnectionFactory + { + /// + /// Creates a connection for Postgresql for the given connection string. + /// + /// The connection string. + /// An initialized DbConnection. + public DbConnection CreateConnection(string nameOrConnectionString) + { + return new NpgsqlConnection(nameOrConnectionString); + } + } +} diff --git a/src/EntityFramework6.Npgsql/NpgsqlMigrationSqlGenerator.cs b/EF6.PG/NpgsqlMigrationSqlGenerator.cs similarity index 96% rename from src/EntityFramework6.Npgsql/NpgsqlMigrationSqlGenerator.cs rename to EF6.PG/NpgsqlMigrationSqlGenerator.cs index cf8f413..c3f26e0 100644 --- a/src/EntityFramework6.Npgsql/NpgsqlMigrationSqlGenerator.cs +++ b/EF6.PG/NpgsqlMigrationSqlGenerator.cs @@ -1,27 +1,4 @@ -#region License -// The PostgreSQL License -// -// Copyright (C) 2016 The Npgsql Development Team -// -// Permission to use, copy, modify, and distribute this software and its -// documentation for any purpose, without fee, and without a written -// agreement is hereby granted, provided that the above copyright notice -// and this paragraph and the following two paragraphs appear in all copies. -// -// IN NO EVENT SHALL THE NPGSQL DEVELOPMENT TEAM BE LIABLE TO ANY PARTY -// FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, -// INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS -// DOCUMENTATION, EVEN IF THE NPGSQL DEVELOPMENT TEAM HAS BEEN ADVISED OF -// THE POSSIBILITY OF SUCH DAMAGE. -// -// THE NPGSQL DEVELOPMENT TEAM SPECIFICALLY DISCLAIMS ANY WARRANTIES, -// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY -// AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS -// ON AN "AS IS" BASIS, AND THE NPGSQL DEVELOPMENT TEAM HAS NO OBLIGATIONS -// TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. -#endregion - -using System; +using System; using System.Collections.Generic; using System.Data.Entity.Migrations.Model; using System.Data.Entity.Migrations.Sql; @@ -436,7 +413,7 @@ protected virtual void Convert(RenameIndexOperation renameIndexOperation) string GetSchemaNameFromFullTableName(string tableFullName) { var dotIndex = tableFullName.IndexOf('.'); - return dotIndex != -1 ? tableFullName.Remove(dotIndex) : "dto"; + return dotIndex != -1 ? tableFullName.Remove(dotIndex) : "dto"; //TODO: Check always setting dto schema if no schema in table name is not bug } diff --git a/src/EntityFramework6.Npgsql/NpgsqlProviderManifest.cs b/EF6.PG/NpgsqlProviderManifest.cs similarity index 94% rename from src/EntityFramework6.Npgsql/NpgsqlProviderManifest.cs rename to EF6.PG/NpgsqlProviderManifest.cs index a6d4350..a76542a 100644 --- a/src/EntityFramework6.Npgsql/NpgsqlProviderManifest.cs +++ b/EF6.PG/NpgsqlProviderManifest.cs @@ -1,27 +1,4 @@ -#region License -// The PostgreSQL License -// -// Copyright (C) 2016 The Npgsql Development Team -// -// Permission to use, copy, modify, and distribute this software and its -// documentation for any purpose, without fee, and without a written -// agreement is hereby granted, provided that the above copyright notice -// and this paragraph and the following two paragraphs appear in all copies. -// -// IN NO EVENT SHALL THE NPGSQL DEVELOPMENT TEAM BE LIABLE TO ANY PARTY -// FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, -// INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS -// DOCUMENTATION, EVEN IF THE NPGSQL DEVELOPMENT TEAM HAS BEEN ADVISED OF -// THE POSSIBILITY OF SUCH DAMAGE. -// -// THE NPGSQL DEVELOPMENT TEAM SPECIFICALLY DISCLAIMS ANY WARRANTIES, -// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY -// AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS -// ON AN "AS IS" BASIS, AND THE NPGSQL DEVELOPMENT TEAM HAS NO OBLIGATIONS -// TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. -#endregion - -using System; +using System; using System.Collections.Generic; using System.Data.Entity; using System.Data.Entity.Core.Common; diff --git a/src/EntityFramework6.Npgsql/NpgsqlRankingNormalization.cs b/EF6.PG/NpgsqlRankingNormalization.cs similarity index 100% rename from src/EntityFramework6.Npgsql/NpgsqlRankingNormalization.cs rename to EF6.PG/NpgsqlRankingNormalization.cs diff --git a/src/EntityFramework6.Npgsql/NpgsqlServices.cs b/EF6.PG/NpgsqlServices.cs similarity index 85% rename from src/EntityFramework6.Npgsql/NpgsqlServices.cs rename to EF6.PG/NpgsqlServices.cs index a7f1abd..4108f76 100644 --- a/src/EntityFramework6.Npgsql/NpgsqlServices.cs +++ b/EF6.PG/NpgsqlServices.cs @@ -1,27 +1,4 @@ -#region License -// The PostgreSQL License -// -// Copyright (C) 2016 The Npgsql Development Team -// -// Permission to use, copy, modify, and distribute this software and its -// documentation for any purpose, without fee, and without a written -// agreement is hereby granted, provided that the above copyright notice -// and this paragraph and the following two paragraphs appear in all copies. -// -// IN NO EVENT SHALL THE NPGSQL DEVELOPMENT TEAM BE LIABLE TO ANY PARTY -// FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, -// INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS -// DOCUMENTATION, EVEN IF THE NPGSQL DEVELOPMENT TEAM HAS BEEN ADVISED OF -// THE POSSIBILITY OF SUCH DAMAGE. -// -// THE NPGSQL DEVELOPMENT TEAM SPECIFICALLY DISCLAIMS ANY WARRANTIES, -// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY -// AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS -// ON AN "AS IS" BASIS, AND THE NPGSQL DEVELOPMENT TEAM HAS NO OBLIGATIONS -// TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. -#endregion - -using System; +using System; using System.Text; using JetBrains.Annotations; using System.Data.Entity.Core.Common; @@ -32,6 +9,7 @@ using Npgsql.SqlGenerators; using DbConnection = System.Data.Common.DbConnection; using DbCommand = System.Data.Common.DbCommand; +using System.Data.Common; #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member @@ -73,6 +51,31 @@ internal DbCommand CreateDbCommand(Version serverVersion, DbCommandTree commandT return command; } + protected override void SetDbParameterValue(DbParameter parameter, TypeUsage parameterType, object value) + { + base.SetDbParameterValue(parameter, parameterType, value); + ConvertValueToNumericIfEnum(parameter); + } + + // Npgsql > 4.0 does strict type checks on integral values and fails with enums passed with numeric DbType. + static void ConvertValueToNumericIfEnum(DbParameter parameter) + { + if (parameter.Value == null) + { + return; + } + + var parameterValueObjectType = parameter.Value.GetType(); + + if (!parameterValueObjectType.IsEnum) + { + return; + } + + var underlyingType = Enum.GetUnderlyingType(parameterValueObjectType); + parameter.Value = Convert.ChangeType(parameter.Value, underlyingType); + } + internal void TranslateCommandTree(Version serverVersion, DbCommandTree commandTree, DbCommand command, bool createParametersForNonSelect = true) { SqlBaseGenerator sqlGenerator; @@ -81,6 +84,7 @@ internal void TranslateCommandTree(Version serverVersion, DbCommandTree commandT DbInsertCommandTree insert; DbUpdateCommandTree update; DbDeleteCommandTree delete; + DbFunctionCommandTree function; if ((select = commandTree as DbQueryCommandTree) != null) sqlGenerator = new SqlSelectGenerator(select); else if ((insert = commandTree as DbInsertCommandTree) != null) @@ -89,6 +93,8 @@ internal void TranslateCommandTree(Version serverVersion, DbCommandTree commandT sqlGenerator = new SqlUpdateGenerator(update); else if ((delete = commandTree as DbDeleteCommandTree) != null) sqlGenerator = new SqlDeleteGenerator(delete); + else if ((function = commandTree as DbFunctionCommandTree) != null) + sqlGenerator = new SqlFunctionGenerator(function); else { // TODO: get a message (unsupported DbCommandTree type) diff --git a/src/EntityFramework6.Npgsql/NpgsqlTextFunctions.cs b/EF6.PG/NpgsqlTextFunctions.cs similarity index 100% rename from src/EntityFramework6.Npgsql/NpgsqlTextFunctions.cs rename to EF6.PG/NpgsqlTextFunctions.cs diff --git a/src/EntityFramework6.Npgsql/NpgsqlTypeFunctions.cs b/EF6.PG/NpgsqlTypeFunctions.cs similarity index 100% rename from src/EntityFramework6.Npgsql/NpgsqlTypeFunctions.cs rename to EF6.PG/NpgsqlTypeFunctions.cs diff --git a/src/EntityFramework6.Npgsql/NpgsqlWeightLabel.cs b/EF6.PG/NpgsqlWeightLabel.cs similarity index 100% rename from src/EntityFramework6.Npgsql/NpgsqlWeightLabel.cs rename to EF6.PG/NpgsqlWeightLabel.cs diff --git a/src/EntityFramework6.Npgsql/Properties/AssemblyInfo.cs b/EF6.PG/Properties/AssemblyInfo.cs similarity index 100% rename from src/EntityFramework6.Npgsql/Properties/AssemblyInfo.cs rename to EF6.PG/Properties/AssemblyInfo.cs diff --git a/src/EntityFramework6.Npgsql/Resources/NpgsqlProviderManifest.Manifest.xml b/EF6.PG/Resources/NpgsqlProviderManifest.Manifest.xml similarity index 100% rename from src/EntityFramework6.Npgsql/Resources/NpgsqlProviderManifest.Manifest.xml rename to EF6.PG/Resources/NpgsqlProviderManifest.Manifest.xml diff --git a/src/EntityFramework6.Npgsql/Resources/NpgsqlSchema.msl b/EF6.PG/Resources/NpgsqlSchema.msl similarity index 100% rename from src/EntityFramework6.Npgsql/Resources/NpgsqlSchema.msl rename to EF6.PG/Resources/NpgsqlSchema.msl diff --git a/src/EntityFramework6.Npgsql/Resources/NpgsqlSchema.ssdl b/EF6.PG/Resources/NpgsqlSchema.ssdl similarity index 99% rename from src/EntityFramework6.Npgsql/Resources/NpgsqlSchema.ssdl rename to EF6.PG/Resources/NpgsqlSchema.ssdl index 50df816..d40b9d4 100644 --- a/src/EntityFramework6.Npgsql/Resources/NpgsqlSchema.ssdl +++ b/EF6.PG/Resources/NpgsqlSchema.ssdl @@ -57,7 +57,7 @@ end as is_identity, false as is_generated, -- default value column - ad.adsrc as default_value + pg_get_expr(ad.adbin, ad.adrelid) as default_value from pg_attribute a join pg_class c on a.attrelid = c.oid @@ -78,7 +78,7 @@ c.condeferrable as is_deferrable, c.condeferred as is_initially_deferred, c.contype as constraint_type, - c.consrc as expression, + pg_get_expr(c.conbin, c.conrelid) as expression, case c.confupdtype when 'c' then 'CASCADE' when 'n' then 'SET NULL' @@ -178,7 +178,7 @@ end as is_identity, false as is_generated, -- default value column - ad.adsrc as default_value + pg_get_expr(ad.adbin, ad.adrelid) as default_value from pg_attribute a join pg_class c on a.attrelid = c.oid diff --git a/src/EntityFramework6.Npgsql/Resources/NpgsqlSchemaV3.ssdl b/EF6.PG/Resources/NpgsqlSchemaV3.ssdl similarity index 99% rename from src/EntityFramework6.Npgsql/Resources/NpgsqlSchemaV3.ssdl rename to EF6.PG/Resources/NpgsqlSchemaV3.ssdl index dd04ebd..5411c61 100644 --- a/src/EntityFramework6.Npgsql/Resources/NpgsqlSchemaV3.ssdl +++ b/EF6.PG/Resources/NpgsqlSchemaV3.ssdl @@ -57,7 +57,7 @@ end as is_identity, false as is_generated, -- default value column - ad.adsrc as default_value + pg_get_expr(ad.adbin, ad.adrelid) as default_value from pg_attribute a join pg_class c on a.attrelid = c.oid @@ -78,7 +78,7 @@ c.condeferrable as is_deferrable, c.condeferred as is_initially_deferred, c.contype as constraint_type, - c.consrc as expression, + pg_get_expr(c.conbin, c.conrelid) as expression, case c.confupdtype when 'c' then 'CASCADE' when 'n' then 'SET NULL' @@ -178,7 +178,7 @@ end as is_identity, false as is_generated, -- default value column - ad.adsrc as default_value + pg_get_expr(ad.adbin, ad.adrelid) as default_value from pg_attribute a join pg_class c on a.attrelid = c.oid diff --git a/src/EntityFramework6.Npgsql/Spatial/PostgisDataReader.cs b/EF6.PG/Spatial/PostgisDataReader.cs similarity index 100% rename from src/EntityFramework6.Npgsql/Spatial/PostgisDataReader.cs rename to EF6.PG/Spatial/PostgisDataReader.cs diff --git a/src/EntityFramework6.Npgsql/Spatial/PostgisServices.cs b/EF6.PG/Spatial/PostgisServices.cs similarity index 100% rename from src/EntityFramework6.Npgsql/Spatial/PostgisServices.cs rename to EF6.PG/Spatial/PostgisServices.cs diff --git a/src/EntityFramework6.Npgsql/SqlGenerators/PendingProjectsNode.cs b/EF6.PG/SqlGenerators/PendingProjectsNode.cs similarity index 53% rename from src/EntityFramework6.Npgsql/SqlGenerators/PendingProjectsNode.cs rename to EF6.PG/SqlGenerators/PendingProjectsNode.cs index 646fba6..346a1e6 100644 --- a/src/EntityFramework6.Npgsql/SqlGenerators/PendingProjectsNode.cs +++ b/EF6.PG/SqlGenerators/PendingProjectsNode.cs @@ -1,27 +1,4 @@ -#region License -// The PostgreSQL License -// -// Copyright (C) 2016 The Npgsql Development Team -// -// Permission to use, copy, modify, and distribute this software and its -// documentation for any purpose, without fee, and without a written -// agreement is hereby granted, provided that the above copyright notice -// and this paragraph and the following two paragraphs appear in all copies. -// -// IN NO EVENT SHALL THE NPGSQL DEVELOPMENT TEAM BE LIABLE TO ANY PARTY -// FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, -// INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS -// DOCUMENTATION, EVEN IF THE NPGSQL DEVELOPMENT TEAM HAS BEEN ADVISED OF -// THE POSSIBILITY OF SUCH DAMAGE. -// -// THE NPGSQL DEVELOPMENT TEAM SPECIFICALLY DISCLAIMS ANY WARRANTIES, -// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY -// AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS -// ON AN "AS IS" BASIS, AND THE NPGSQL DEVELOPMENT TEAM HAS NO OBLIGATIONS -// TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. -#endregion - -using System.Collections.Generic; +using System.Collections.Generic; namespace Npgsql.SqlGenerators { diff --git a/src/EntityFramework6.Npgsql/SqlGenerators/SqlBaseGenerator.cs b/EF6.PG/SqlGenerators/SqlBaseGenerator.cs similarity index 98% rename from src/EntityFramework6.Npgsql/SqlGenerators/SqlBaseGenerator.cs rename to EF6.PG/SqlGenerators/SqlBaseGenerator.cs index c2247fc..b36413a 100644 --- a/src/EntityFramework6.Npgsql/SqlGenerators/SqlBaseGenerator.cs +++ b/EF6.PG/SqlGenerators/SqlBaseGenerator.cs @@ -1,27 +1,4 @@ -#region License -// The PostgreSQL License -// -// Copyright (C) 2016 The Npgsql Development Team -// -// Permission to use, copy, modify, and distribute this software and its -// documentation for any purpose, without fee, and without a written -// agreement is hereby granted, provided that the above copyright notice -// and this paragraph and the following two paragraphs appear in all copies. -// -// IN NO EVENT SHALL THE NPGSQL DEVELOPMENT TEAM BE LIABLE TO ANY PARTY -// FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, -// INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS -// DOCUMENTATION, EVEN IF THE NPGSQL DEVELOPMENT TEAM HAS BEEN ADVISED OF -// THE POSSIBILITY OF SUCH DAMAGE. -// -// THE NPGSQL DEVELOPMENT TEAM SPECIFICALLY DISCLAIMS ANY WARRANTIES, -// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY -// AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS -// ON AN "AS IS" BASIS, AND THE NPGSQL DEVELOPMENT TEAM HAS NO OBLIGATIONS -// TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. -#endregion - -using System; +using System; using System.Collections.Generic; using System.Data.Common; using System.Diagnostics; diff --git a/src/EntityFramework6.Npgsql/SqlGenerators/SqlDeleteGenerator.cs b/EF6.PG/SqlGenerators/SqlDeleteGenerator.cs similarity index 53% rename from src/EntityFramework6.Npgsql/SqlGenerators/SqlDeleteGenerator.cs rename to EF6.PG/SqlGenerators/SqlDeleteGenerator.cs index 0766ac0..a24eb92 100644 --- a/src/EntityFramework6.Npgsql/SqlGenerators/SqlDeleteGenerator.cs +++ b/EF6.PG/SqlGenerators/SqlDeleteGenerator.cs @@ -1,27 +1,4 @@ -#region License -// The PostgreSQL License -// -// Copyright (C) 2016 The Npgsql Development Team -// -// Permission to use, copy, modify, and distribute this software and its -// documentation for any purpose, without fee, and without a written -// agreement is hereby granted, provided that the above copyright notice -// and this paragraph and the following two paragraphs appear in all copies. -// -// IN NO EVENT SHALL THE NPGSQL DEVELOPMENT TEAM BE LIABLE TO ANY PARTY -// FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, -// INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS -// DOCUMENTATION, EVEN IF THE NPGSQL DEVELOPMENT TEAM HAS BEEN ADVISED OF -// THE POSSIBILITY OF SUCH DAMAGE. -// -// THE NPGSQL DEVELOPMENT TEAM SPECIFICALLY DISCLAIMS ANY WARRANTIES, -// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY -// AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS -// ON AN "AS IS" BASIS, AND THE NPGSQL DEVELOPMENT TEAM HAS NO OBLIGATIONS -// TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. -#endregion - -using System; +using System; using System.Data.Common; using System.Data.Entity.Core.Common.CommandTrees; diff --git a/EF6.PG/SqlGenerators/SqlFunctionGenerator.cs b/EF6.PG/SqlGenerators/SqlFunctionGenerator.cs new file mode 100644 index 0000000..25ed47c --- /dev/null +++ b/EF6.PG/SqlGenerators/SqlFunctionGenerator.cs @@ -0,0 +1,22 @@ +using System.Linq; +using System.Data.Common; +using System.Data.Entity.Core.Common.CommandTrees; + +namespace Npgsql.SqlGenerators +{ + class SqlFunctionGenerator : SqlBaseGenerator + { + readonly DbFunctionCommandTree _commandTree; + + public SqlFunctionGenerator(DbFunctionCommandTree commandTree) + { + _commandTree = commandTree; + } + + public override void BuildCommand(DbCommand command) + { + var paramStr = string.Join(",", command.Parameters.OfType().Select(x => "@" + x.ParameterName).ToArray()); + command.CommandText = $"SELECT * FROM { QuoteIdentifier(_commandTree.EdmFunction.Schema) }.{ QuoteIdentifier(_commandTree.EdmFunction.Name) } ({paramStr})"; + } + } +} diff --git a/src/EntityFramework6.Npgsql/SqlGenerators/SqlInsertGenerator.cs b/EF6.PG/SqlGenerators/SqlInsertGenerator.cs similarity index 60% rename from src/EntityFramework6.Npgsql/SqlGenerators/SqlInsertGenerator.cs rename to EF6.PG/SqlGenerators/SqlInsertGenerator.cs index 0e0fe5a..856a31a 100644 --- a/src/EntityFramework6.Npgsql/SqlGenerators/SqlInsertGenerator.cs +++ b/EF6.PG/SqlGenerators/SqlInsertGenerator.cs @@ -1,27 +1,4 @@ -#region License -// The PostgreSQL License -// -// Copyright (C) 2016 The Npgsql Development Team -// -// Permission to use, copy, modify, and distribute this software and its -// documentation for any purpose, without fee, and without a written -// agreement is hereby granted, provided that the above copyright notice -// and this paragraph and the following two paragraphs appear in all copies. -// -// IN NO EVENT SHALL THE NPGSQL DEVELOPMENT TEAM BE LIABLE TO ANY PARTY -// FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, -// INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS -// DOCUMENTATION, EVEN IF THE NPGSQL DEVELOPMENT TEAM HAS BEEN ADVISED OF -// THE POSSIBILITY OF SUCH DAMAGE. -// -// THE NPGSQL DEVELOPMENT TEAM SPECIFICALLY DISCLAIMS ANY WARRANTIES, -// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY -// AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS -// ON AN "AS IS" BASIS, AND THE NPGSQL DEVELOPMENT TEAM HAS NO OBLIGATIONS -// TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. -#endregion - -using System; +using System; using System.Collections.Generic; using System.Data.Common; using System.Data.Entity.Core.Common.CommandTrees; diff --git a/src/EntityFramework6.Npgsql/SqlGenerators/SqlSelectGenerator.cs b/EF6.PG/SqlGenerators/SqlSelectGenerator.cs similarity index 82% rename from src/EntityFramework6.Npgsql/SqlGenerators/SqlSelectGenerator.cs rename to EF6.PG/SqlGenerators/SqlSelectGenerator.cs index 22d22e6..ed2616a 100644 --- a/src/EntityFramework6.Npgsql/SqlGenerators/SqlSelectGenerator.cs +++ b/EF6.PG/SqlGenerators/SqlSelectGenerator.cs @@ -1,27 +1,4 @@ -#region License -// The PostgreSQL License -// -// Copyright (C) 2016 The Npgsql Development Team -// -// Permission to use, copy, modify, and distribute this software and its -// documentation for any purpose, without fee, and without a written -// agreement is hereby granted, provided that the above copyright notice -// and this paragraph and the following two paragraphs appear in all copies. -// -// IN NO EVENT SHALL THE NPGSQL DEVELOPMENT TEAM BE LIABLE TO ANY PARTY -// FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, -// INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS -// DOCUMENTATION, EVEN IF THE NPGSQL DEVELOPMENT TEAM HAS BEEN ADVISED OF -// THE POSSIBILITY OF SUCH DAMAGE. -// -// THE NPGSQL DEVELOPMENT TEAM SPECIFICALLY DISCLAIMS ANY WARRANTIES, -// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY -// AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS -// ON AN "AS IS" BASIS, AND THE NPGSQL DEVELOPMENT TEAM HAS NO OBLIGATIONS -// TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. -#endregion - -using System; +using System; using System.Linq; using System.Data.Common; using System.Diagnostics; diff --git a/src/EntityFramework6.Npgsql/SqlGenerators/SqlUpdateGenerator.cs b/EF6.PG/SqlGenerators/SqlUpdateGenerator.cs similarity index 58% rename from src/EntityFramework6.Npgsql/SqlGenerators/SqlUpdateGenerator.cs rename to EF6.PG/SqlGenerators/SqlUpdateGenerator.cs index fde7c7a..acf3fb3 100644 --- a/src/EntityFramework6.Npgsql/SqlGenerators/SqlUpdateGenerator.cs +++ b/EF6.PG/SqlGenerators/SqlUpdateGenerator.cs @@ -1,27 +1,4 @@ -#region License -// The PostgreSQL License -// -// Copyright (C) 2016 The Npgsql Development Team -// -// Permission to use, copy, modify, and distribute this software and its -// documentation for any purpose, without fee, and without a written -// agreement is hereby granted, provided that the above copyright notice -// and this paragraph and the following two paragraphs appear in all copies. -// -// IN NO EVENT SHALL THE NPGSQL DEVELOPMENT TEAM BE LIABLE TO ANY PARTY -// FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, -// INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS -// DOCUMENTATION, EVEN IF THE NPGSQL DEVELOPMENT TEAM HAS BEEN ADVISED OF -// THE POSSIBILITY OF SUCH DAMAGE. -// -// THE NPGSQL DEVELOPMENT TEAM SPECIFICALLY DISCLAIMS ANY WARRANTIES, -// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY -// AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS -// ON AN "AS IS" BASIS, AND THE NPGSQL DEVELOPMENT TEAM HAS NO OBLIGATIONS -// TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. -#endregion - -using System; +using System; using System.Data.Common; using System.Data.Entity.Core.Common.CommandTrees; diff --git a/EF6.PG/SqlGenerators/StringPair.cs b/EF6.PG/SqlGenerators/StringPair.cs new file mode 100644 index 0000000..72d2512 --- /dev/null +++ b/EF6.PG/SqlGenerators/StringPair.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using JetBrains.Annotations; + +namespace Npgsql.SqlGenerators +{ + /// + /// Used for lookup in a Dictionary, since Tuple is not available in .NET 3.5 + /// + internal class StringPair + { + public string Item1 { get; } + public string Item2 { get; } + + public StringPair(string s1, string s2) + { + Item1 = s1; + Item2 = s2; + } + + public override bool Equals([CanBeNull] object obj) + { + var o = obj as StringPair; + if (o == null) + return false; + + return Item1 == o.Item1 && Item2 == o.Item2; + } + + public override int GetHashCode() + => (Item1 + "." + Item2).GetHashCode(); + } +} diff --git a/src/EntityFramework6.Npgsql/SqlGenerators/VisitedExpression.cs b/EF6.PG/SqlGenerators/VisitedExpression.cs similarity index 97% rename from src/EntityFramework6.Npgsql/SqlGenerators/VisitedExpression.cs rename to EF6.PG/SqlGenerators/VisitedExpression.cs index 2621c74..b952deb 100644 --- a/src/EntityFramework6.Npgsql/SqlGenerators/VisitedExpression.cs +++ b/EF6.PG/SqlGenerators/VisitedExpression.cs @@ -1,27 +1,4 @@ -#region License -// The PostgreSQL License -// -// Copyright (C) 2016 The Npgsql Development Team -// -// Permission to use, copy, modify, and distribute this software and its -// documentation for any purpose, without fee, and without a written -// agreement is hereby granted, provided that the above copyright notice -// and this paragraph and the following two paragraphs appear in all copies. -// -// IN NO EVENT SHALL THE NPGSQL DEVELOPMENT TEAM BE LIABLE TO ANY PARTY -// FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, -// INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS -// DOCUMENTATION, EVEN IF THE NPGSQL DEVELOPMENT TEAM HAS BEEN ADVISED OF -// THE POSSIBILITY OF SUCH DAMAGE. -// -// THE NPGSQL DEVELOPMENT TEAM SPECIFICALLY DISCLAIMS ANY WARRANTIES, -// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY -// AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS -// ON AN "AS IS" BASIS, AND THE NPGSQL DEVELOPMENT TEAM HAS NO OBLIGATIONS -// TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. -#endregion - -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; diff --git a/EF6.PG/content/App.config.install.xdt b/EF6.PG/content/App.config.install.xdt new file mode 100644 index 0000000..ace92ed --- /dev/null +++ b/EF6.PG/content/App.config.install.xdt @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/EF6.PG/content/Web.config.install.xdt b/EF6.PG/content/Web.config.install.xdt new file mode 100644 index 0000000..ace92ed --- /dev/null +++ b/EF6.PG/content/Web.config.install.xdt @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/EF6.PG/content/net45/App.config.transform b/EF6.PG/content/net45/App.config.transform new file mode 100644 index 0000000..1dad58e --- /dev/null +++ b/EF6.PG/content/net45/App.config.transform @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/EF6.PG/content/net45/Web.config.transform b/EF6.PG/content/net45/Web.config.transform new file mode 100644 index 0000000..1dad58e --- /dev/null +++ b/EF6.PG/content/net45/Web.config.transform @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/EF6.PG/content/net461/App.config.transform b/EF6.PG/content/net461/App.config.transform new file mode 100644 index 0000000..0899448 --- /dev/null +++ b/EF6.PG/content/net461/App.config.transform @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/EF6.PG/content/net461/Web.config.transform b/EF6.PG/content/net461/Web.config.transform new file mode 100644 index 0000000..0899448 --- /dev/null +++ b/EF6.PG/content/net461/Web.config.transform @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/EF6.PG/postgresql.png b/EF6.PG/postgresql.png new file mode 100644 index 0000000..3a21b19 Binary files /dev/null and b/EF6.PG/postgresql.png differ diff --git a/EntityFramework6.Npgsql.sln b/EntityFramework6.Npgsql.sln index 54bf88e..d04e93d 100644 --- a/EntityFramework6.Npgsql.sln +++ b/EntityFramework6.Npgsql.sln @@ -1,20 +1,17 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 +Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.27703.2035 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{4A5A60DD-41B6-40BF-B677-227A921ECCC8}" ProjectSection(SolutionItems) = preProject + Directory.Build.props = Directory.Build.props + Directory.Build.targets = Directory.Build.targets Npgsql.snk = Npgsql.snk EndProjectSection EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{8537E50E-CF7F-49CB-B4EF-3E2A1B11F050}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EF6.PG", "EF6.PG\EF6.PG.csproj", "{3EC85CBA-5B79-11E3-8104-0022198AB089}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{ED612DB1-AB32-4603-95E7-891BACA71C39}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EntityFramework6.Npgsql", "src\EntityFramework6.Npgsql\EntityFramework6.Npgsql.csproj", "{3EC85CBA-5B79-11E3-8104-0022198AB089}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EntityFramework6.Npgsql.Tests", "test\EntityFramework6.Npgsql.Tests\EntityFramework6.Npgsql.Tests.csproj", "{4A0A42DE-C8B8-11E4-8EC9-005056A163A4}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EF6.PG.Tests", "EF6.PG.Tests\EF6.PG.Tests.csproj", "{4A0A42DE-C8B8-11E4-8EC9-005056A163A4}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -34,10 +31,6 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {3EC85CBA-5B79-11E3-8104-0022198AB089} = {8537E50E-CF7F-49CB-B4EF-3E2A1B11F050} - {4A0A42DE-C8B8-11E4-8EC9-005056A163A4} = {ED612DB1-AB32-4603-95E7-891BACA71C39} - EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {84B4C9EA-ED4F-4E87-8809-297958315622} EndGlobalSection diff --git a/EntityFramework6.Npgsql.sln.DotSettings b/EntityFramework6.Npgsql.sln.DotSettings index 78c61b1..5dfab15 100644 --- a/EntityFramework6.Npgsql.sln.DotSettings +++ b/EntityFramework6.Npgsql.sln.DotSettings @@ -58,6 +58,7 @@ True True True + True True True True diff --git a/README.md b/README.md new file mode 100644 index 0000000..a00fdb6 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# Entity Framework 6 Provider for PostgreSQL + +This is the Npgsql PostgreSQL provider for Entity Framework 6; note that this is the old, non-core version of EF. For the EF Core provider, see https://github.com/npgsql/efcore.pg. + +Like non-core Entity Framework 6, this provider is no longer being maintained. It is unlikely that any enhancements or bug fixes will be worked upon, unless they're absolutely critical. \ No newline at end of file diff --git a/doc/index.md b/doc/index.md deleted file mode 100644 index 0a73365..0000000 --- a/doc/index.md +++ /dev/null @@ -1,92 +0,0 @@ ---- -layout: doc -title: Entity Framework 6 ---- - -Npgsql has an Entity Framework 6 provider. You can use it by installing the -[EntityFramework6.Npgsql](https://www.nuget.org/packages/EntityFramework6.Npgsql/) nuget. - -## Guid Support ## - -Npgsql EF migrations support uses `uuid_generate_v4()` function to generate guids. -In order to have access to this function, you have to install the extension uuid-ossp through the following command: - -```sql -create extension "uuid-ossp"; -``` - -If you don't have this extension installed, when you run Npgsql migrations you will get the following error message: - -``` -ERROR: function uuid_generate_v4() does not exist -``` - -If the database is being created by Npgsql Migrations, you will need to -[run the `create extension` command in the `template1` database](http://stackoverflow.com/a/11584751). -This way, when the new database is created, the extension will be installed already. - -## Template Database ## - -When the Entity Framework 6 provider creates a database, it issues a simple `CREATE DATABASE` command. -In PostgreSQL, this implicitly uses `template1` as the template - anything existing in `template1` will -be copied to your new database. If you wish to change the database used as a template, you can specify -the `EF Template Database` connection string parameter. For more info see the -[PostgreSQL docs](https://www.postgresql.org/docs/current/static/sql-createdatabase.html). - -## Customizing DataReader Behavior ## - -You can use [an Entity Framework 6 IDbCommandInterceptor](https://msdn.microsoft.com/en-us/library/dn469464(v=vs.113).aspx) to wrap the `DataReader` instance returned by Npgsql when Entity Framework executes queries. This is possible using a ```DbConfiguration``` class. - -Example use cases: -- Forcing all returned ```DateTime``` and ```DateTimeOffset``` values to be in the UTC timezone. -- Preventing accidental insertion of DateTime values having ```DateTimeKind.Unspecified```. -- Forcing all postgres date/time types to be returned to Entity Framework as ```DateTimeOffset```. - -```c# -[DbConfigurationType(typeof(AppDbContextConfiguration))] -public class AppDbContext : DbContext -{ - // ... -} - -public class AppDbContextConfiguration : DbConfiguration -{ - public AppDbContextConfiguration() - { - this.AddInterceptor(new MyEntityFrameworkInterceptor()); - } -} - -class MyEntityFrameworkInterceptor : DbCommandInterceptor -{ - public override void ReaderExecuted( - DbCommand command, - DbCommandInterceptionContext interceptionContext) - { - if (interceptionContext.Result == null) return; - interceptionContext.Result = new WrappingDbDataReader(interceptionContext.Result); - } - - public override void ScalarExecuted( - DbCommand command, - DbCommandInterceptionContext interceptionContext) - { - interceptionContext.Result = ModifyReturnValues(interceptionContext.Result); - } - - static object ModifyReturnValues(object result) - { - // Transform and then - return result; - } -} - -class WrappingDbDataReader : DbDataReader, IDataReader -{ - // Wrap an existing DbDataReader, proxy all calls to the underlying instance, - // modify return values and/or parameters as needed... - public WrappingDbDataReader(DbDataReader reader) - { - } -} -``` diff --git a/doc/toc.md b/doc/toc.md deleted file mode 100644 index 0d45642..0000000 --- a/doc/toc.md +++ /dev/null @@ -1 +0,0 @@ -# [Getting Started](index.md) diff --git a/src/EntityFramework6.Npgsql/EntityFramework6.Npgsql.csproj b/src/EntityFramework6.Npgsql/EntityFramework6.Npgsql.csproj deleted file mode 100644 index b0bb8ff..0000000 --- a/src/EntityFramework6.Npgsql/EntityFramework6.Npgsql.csproj +++ /dev/null @@ -1,45 +0,0 @@ - - - PostgreSQL provider for Entity Framework 6 - Shay Rojansky;Emil Lenngren;Francisco Figueiredo Jr.;Kenji Uno - Copyright 2018 © The Npgsql Development Team - Npgsql - npgsql postgresql postgres data database entity framework ef orm - 3.2.0 - latest - net45 - true - CS1591 - true - Npgsql - true - ../../Npgsql.snk - true - true - http://www.npgsql.org - http://www.npgsql.org/img/postgresql.gif - https://raw.githubusercontent.com/npgsql/npgsql/master/LICENSE.txt - git - git://github.com/npgsql/EntityFramework6.Npgsql - true - - - - - - - - - - - - - - - - - - - - - diff --git a/src/EntityFramework6.Npgsql/NpgsqlConnectionFactory.cs b/src/EntityFramework6.Npgsql/NpgsqlConnectionFactory.cs deleted file mode 100644 index 926d39c..0000000 --- a/src/EntityFramework6.Npgsql/NpgsqlConnectionFactory.cs +++ /dev/null @@ -1,44 +0,0 @@ -#region License -// The PostgreSQL License -// -// Copyright (C) 2016 The Npgsql Development Team -// -// Permission to use, copy, modify, and distribute this software and its -// documentation for any purpose, without fee, and without a written -// agreement is hereby granted, provided that the above copyright notice -// and this paragraph and the following two paragraphs appear in all copies. -// -// IN NO EVENT SHALL THE NPGSQL DEVELOPMENT TEAM BE LIABLE TO ANY PARTY -// FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, -// INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS -// DOCUMENTATION, EVEN IF THE NPGSQL DEVELOPMENT TEAM HAS BEEN ADVISED OF -// THE POSSIBILITY OF SUCH DAMAGE. -// -// THE NPGSQL DEVELOPMENT TEAM SPECIFICALLY DISCLAIMS ANY WARRANTIES, -// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY -// AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS -// ON AN "AS IS" BASIS, AND THE NPGSQL DEVELOPMENT TEAM HAS NO OBLIGATIONS -// TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. -#endregion - -using System.Data.Common; -using System.Data.Entity.Infrastructure; - -namespace Npgsql -{ - /// - /// Instances of this class are used to create DbConnection objects for Postgresql - /// - public class NpgsqlConnectionFactory : IDbConnectionFactory - { - /// - /// Creates a connection for Postgresql for the given connection string. - /// - /// The connection string. - /// An initialized DbConnection. - public DbConnection CreateConnection(string nameOrConnectionString) - { - return new NpgsqlConnection(nameOrConnectionString); - } - } -} diff --git a/src/EntityFramework6.Npgsql/SqlGenerators/StringPair.cs b/src/EntityFramework6.Npgsql/SqlGenerators/StringPair.cs deleted file mode 100644 index c605574..0000000 --- a/src/EntityFramework6.Npgsql/SqlGenerators/StringPair.cs +++ /dev/null @@ -1,58 +0,0 @@ -#region License -// The PostgreSQL License -// -// Copyright (C) 2016 The Npgsql Development Team -// -// Permission to use, copy, modify, and distribute this software and its -// documentation for any purpose, without fee, and without a written -// agreement is hereby granted, provided that the above copyright notice -// and this paragraph and the following two paragraphs appear in all copies. -// -// IN NO EVENT SHALL THE NPGSQL DEVELOPMENT TEAM BE LIABLE TO ANY PARTY -// FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, -// INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS -// DOCUMENTATION, EVEN IF THE NPGSQL DEVELOPMENT TEAM HAS BEEN ADVISED OF -// THE POSSIBILITY OF SUCH DAMAGE. -// -// THE NPGSQL DEVELOPMENT TEAM SPECIFICALLY DISCLAIMS ANY WARRANTIES, -// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY -// AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS -// ON AN "AS IS" BASIS, AND THE NPGSQL DEVELOPMENT TEAM HAS NO OBLIGATIONS -// TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. -#endregion - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using JetBrains.Annotations; - -namespace Npgsql.SqlGenerators -{ - /// - /// Used for lookup in a Dictionary, since Tuple is not available in .NET 3.5 - /// - internal class StringPair - { - public string Item1 { get; } - public string Item2 { get; } - - public StringPair(string s1, string s2) - { - Item1 = s1; - Item2 = s2; - } - - public override bool Equals([CanBeNull] object obj) - { - var o = obj as StringPair; - if (o == null) - return false; - - return Item1 == o.Item1 && Item2 == o.Item2; - } - - public override int GetHashCode() - => (Item1 + "." + Item2).GetHashCode(); - } -} diff --git a/src/EntityFramework6.Npgsql/install.ps1 b/src/EntityFramework6.Npgsql/install.ps1 deleted file mode 100644 index b6b6c15..0000000 --- a/src/EntityFramework6.Npgsql/install.ps1 +++ /dev/null @@ -1,3 +0,0 @@ -param($installPath, $toolsPath, $package, $project) - -Add-EFProvider $project 'Npgsql' 'Npgsql.NpgsqlServices, EntityFramework6.Npgsql' diff --git a/test/EntityFramework6.Npgsql.Tests/EntityFramework6.Npgsql.Tests.csproj b/test/EntityFramework6.Npgsql.Tests/EntityFramework6.Npgsql.Tests.csproj deleted file mode 100644 index de91a6a..0000000 --- a/test/EntityFramework6.Npgsql.Tests/EntityFramework6.Npgsql.Tests.csproj +++ /dev/null @@ -1,16 +0,0 @@ - - - latest - net45 - - - - - - - - - - - -