Skip to content
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

Support for EFMigration and Database creation #91

Merged
merged 10 commits into from Feb 20, 2014

Conversation

DavidKarlas
Copy link
Contributor

After following this guide for EntityFramework http://fxjr.blogspot.com/2013/06/npgsql-code-first-entity-framework-431.html I realized there is no support for automatic creation of database and tables... So i created support for DatabaseExist, DatabaseDelete and DatabaseCreate in NpgsqlServices.cs. Also added NpgsqlMigrationSqlGenerator in constructor so it's loaded by dependency injector...

Wrote NpgsqlMigrationSqlGenerator which does not handle Procedures and switching type from int to serial(doesn't add default value to new sequence...) plus I'm not sure how well Indexes work...

I will soon start using this migration on project I'm starting so I'm making this pull request to make people aware of it if someone wants to play with it. You could also merge it it effects only #if ENTITIES6...

My point is... its not complete yet...

@DavidKarlas
Copy link
Contributor Author

I'm working with classic BloggingContex example with classes Blog and Post... This is how my app.config looks like:

<?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" />
  <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <entityFramework>
    <providers>
      <provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, Npgsql.EntityFramework"></provider>
    </providers>
    <defaultConnectionFactory type="Npgsql.NpgsqlFactory, Npgsql" />
  </entityFramework>
    <connectionStrings>
        <add name="BloggingContext" providerName="Npgsql" connectionString="server=localhost;port=5432;userid=npgsql_tests;password=npgsql_tests;database=ef6_code_first_sample" />
    </connectionStrings>
    <system.data>
        <DbProviderFactories>
            <remove invariant="Npgsql" />
            <add name="Npgsql Data Provider" invariant="Npgsql" support="FF" description=".Net Framework Data Provider for Postgresql" type="Npgsql.NpgsqlFactory, Npgsql" />
        </DbProviderFactories>
    </system.data>
</configuration>

@franciscojunior
Copy link
Member

Hi, David!

Thank you for your pull request! This will be a great addition to Npgsql EF support.

I'll check it and if I have any problems I'll contact you. Then I'll merge it in the current master branch!

sql.Append("\" ");
AppendColumnType(column, sql, true);

if (column.IsNullable ?? false)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this test is backwards.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you think that if IsNullable is not set should mean that column has to be NOT NULL? I think that if is not set it should be nullable...

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think "NOT NULL" should only be added if IsNullable has a value and it's value is false.

You're adding NOT NULL when IsNullable is true.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if(column.IsNullable != null && !column.IsNullable) {...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. Feeling much stupid atm :)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also simply do if(column.IsNullable == false).

@franciscojunior
Copy link
Member

Excellent!

I tested it here and it worked perfectly!

Do you think it would be possible to add some unit tests to the NpgsqlMigrationSqlGenerator class? Maybe adding some handcrafted migrationOperations ? I mean, we could create some fake migrationOperations and compare the expected command creation with the actual commands created? This way we wouldn't need to create a full blown EF project but we still could test the command generation correctness?

What do you think?

@DavidKarlas
Copy link
Contributor Author

I might do UnitTests this weekend if i get some time ;)
Would you prefer to test generated strings or to connect to database and compare with

select column_name, data_type, is_nullable... from information_schema.columns where table_name = 'table';

One is faster other is more effective in my opinion...

@franciscojunior
Copy link
Member

We should go with the second option. I agree with you that it is more effective.

@franciscojunior
Copy link
Member

Another detail I noticed is that those changes fail to build in the Npgsql project for visual studio 2013 when using the net35 configuration. This is the reported error:

[Csc] Npgsql\NpgsqlServices.cs(113, 33): error CS0115: 'Npgsql.NpgsqlServices.DbDatabaseExists(System.Data.Common.DbConnection, int?, System.Data.Metadata.Edm.StoreItemCollection)': no suitable method found to override
[16:35:52][Csc] Npgsql\NpgsqlServices.cs(126, 33): error CS0115: 'Npgsql.NpgsqlServices.DbCreateDatabase(System.Data.Common.DbConnection, int?, System.Data.Metadata.Edm.StoreItemCollection)': no suitable method found to override
[16:35:52][Csc] Npgsql\NpgsqlServices.cs(137, 33): error CS0115: 'Npgsql.NpgsqlServices.DbDeleteDatabase(System.Data.Common.DbConnection, int?, System.Data.Metadata.Edm.StoreItemCollection)': no suitable method found to override

I tested it here and I think you can wrap this code with a #ifdef NET40 letting the UsingPostgresDBConnection out of the #if.

private void CreateExtension(string exensionName)
{
//This is compatible only with server 9.1+
if (serverVersion.Major > 9 || (serverVersion.Major == 9 && serverVersion.Minor >= 1))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If someone will work on this code notice that extension like UUID will not be created on older server versions...

@franciscojunior
Copy link
Member

Hi, David!

We merged pull request #110 which made your pull request not apply cleanly anymore. Would you mind to rebase it on current master?

Thanks in advance.

@DavidKarlas
Copy link
Contributor Author

I reset my Master to upstream Master and added NpgsqlMigrationSqlGenerator.cs only in Npgsql.EntityFramework project(since this is only EF6+ working code(MigrationSqlGenerator had some changes between EF4 and EF6)).
I also changed NpgsqlServices to be mergable again plus added #if EF6 around DB creation methods to compile on .Net35 build properly(EF6 does not support .Net 3.5)...

I will now start looking into creating UnitTests...

@franciscojunior
Copy link
Member

Excellent, David!

Your pull request is one I'd like to include in next 2.1 release before we
do the feature freeze. As we are doing a big push in the ef area with this
release, I think your patch to allow dB creation and migration is also
desirable to be included.

I'm looking forward your tests. I could only test the db creation in my
test app.
Em 07/12/2013 08:43, "David Karlaš" notifications@github.com escreveu:

I reset my Master to upstream Master and added
NpgsqlMigrationSqlGenerator.cs only in Npgsql.EntityFramework project(since
this is only EF6+ working code(MigrationSqlGenerator had some changes
between EF4 and EF6)).
I also changed NpgsqlServices to be mergable again plus added #if EF6
around DB creation methods to compile on .Net35 build properly(EF6 does not
support .Net 3.5)...

I will now start looking into creating UnitTests...


Reply to this email directly or view it on GitHubhttps://github.com//pull/91#issuecomment-30052303
.

@DavidKarlas
Copy link
Contributor Author

It seems like current NpgsqlTests project does not have EntityFramework included... Will you guys create NpgsqlTests.EntityFramework project which will have references to Npgsql.EntityFramework and EntityFramework nuget package?

@roji
Copy link
Member

roji commented Dec 7, 2013

@DavidKarlas, there is no reason not to add a project reference from NpgsqlTests to Npgsql.EntityFramework (and even to Npgsql.EntityFrameworkLegacy), no need for extra projects... Go ahead and do so in your pull request,

@franciscojunior
Copy link
Member

Hi David.

There is this pull request #119 which adds some changes to some EF support files. Do you think they have impact in your database creation support? I also asked Kenji who created #119 to have a look so he can give us some feedback about that.

@kenjiuno
Copy link
Contributor

Hi David.

I have pull request #119 for updating Npgsql's provider manifest. It will affect EF support.

I have watched your changes. I think your patch won't be affected.

If you can prepare unit tests for your pull request, I'm willing to test it with my patch. :)

@DavidKarlas
Copy link
Contributor Author

To be honest I'm not 100% what #119 is doing. But I think there won't be problems.

I was working on how to make unit tests for this migrations during weekend. And I will probably make one or two tests against DB and rest will be string compare based testing because It's hard to create migrations test because have to modify classes and then run AddMigration in Nuget console...(this sounded simple but It's nasty)

@franciscojunior
Copy link
Member

To be honest I'm not 100% what #119 is doing. But I think there won't be problems.

I also think there won't be problems.

I was working on how to make unit tests for this migrations during weekend. And I will probably make one or two tests against DB and rest will be string compare based testing because It's hard to create migrations test because have to modify classes and then run AddMigration in Nuget console...(this sounded simple but It's nasty)

Ok. I think string comparison will work too.

@roji
Copy link
Member

roji commented Dec 12, 2013

@DavidKarlas, don't mean to press but have you had any time to work on the unit tests? I'm only asking because we're waiting on this pull request to start the 2.1 release cycle

@DavidKarlas
Copy link
Contributor Author

I will do it this weekend ;) Hope it's not too late...

@roji
Copy link
Member

roji commented Dec 13, 2013

Thanks :) of course it isn't too late...

@roji
Copy link
Member

roji commented Dec 20, 2013

I think we really should be freezing version 2.1 soon, and are waiting only for this. I'd say if you can't get this done this weekend, we can leave it for the next release, ok?

@DavidKarlas
Copy link
Contributor Author

Sorry for delaying this for one week but could we skip this feature for 2.1 release because I done only few tests so far plus I'm not happy about only supporting server 9.3(because CREATE SCHEMA IF NOT EXISTS)... Plus there are probably some bugs... Plus it seems like this not very demending feature atm...

@roji
Copy link
Member

roji commented Dec 20, 2013

No problem @DavidKarlas, if you're not 100% happy with it, take your time and work on it for the next release...

@DavidKarlas
Copy link
Contributor Author

I'm still alive :) I was hyped on NetDuino and some other stuff...
I did all basic UnitTests and found few bugs... Now testing on existing nicely sized context with few migrations all is fine except this MVC application is using AspNet authorization which creates Tables at runtime but there is bug in EF I'm hoping you guys can upvote this on EF issue tracker TY
https://entityframework.codeplex.com/workitem/371

@franciscojunior
Copy link
Member

I'm still alive :) I was hyped on NetDuino and some other stuff...

Welcome back! :)

I did all basic UnitTests and found few bugs... Now testing on existing nicely sized context with few migrations all is fine except this MVC application is using AspNet authorization which creates Tables at runtime but there is bug in EF I'm hoping you guys can upvote this on EF issue tracker TY
https://entityframework.codeplex.com/workitem/371

Excellent!!

I'll have a look at this EF bug.

Please, let us know if you have any problems merging your code back to Npgsql code base. We made a lot of changes.

Thanks in advance.

@roji
Copy link
Member

roji commented Feb 12, 2014

OK. So if the npgsql_tests user has to have database create/drop permissions for the EF tests, we might as well make it create the non-EF npgsql_tests database as well like @DavidKarlas suggested...

@franciscojunior
Copy link
Member

On Wed, Feb 12, 2014 at 3:38 PM, Shay Rojansky notifications@github.comwrote:

OK. So if the npgsql_tests user has to have database create/drop
permissions for the EF tests, we might as well make it create the non-EF
npgsql_tests database as well like @DavidKarlashttps://github.com/DavidKarlassuggested...

Agreed!

+1


Reply to this email directly or view it on GitHubhttps://github.com//pull/91#issuecomment-34894161
.

Regards,

Francisco Figueiredo Jr.
Npgsql Lead Developer
http://www.npgsql.org
http://gplus.to/franciscojunior
http://fxjr.blogspot.com
http://twitter.com/franciscojunior

@franciscojunior
Copy link
Member

Shay, do you think it would be too much annoying to raise the requirements
to run our tests the use of a user with createdb permissions?

On Wed, Feb 12, 2014 at 4:22 PM, Francisco Figueiredo Jr. <
francisco@npgsql.org> wrote:

On Wed, Feb 12, 2014 at 3:38 PM, Shay Rojansky notifications@github.comwrote:

OK. So if the npgsql_tests user has to have database create/drop
permissions for the EF tests, we might as well make it create the non-EF
npgsql_tests database as well like @DavidKarlashttps://github.com/DavidKarlassuggested...

Agreed!

+1


Reply to this email directly or view it on GitHubhttps://github.com//pull/91#issuecomment-34894161
.

Regards,

Francisco Figueiredo Jr.
Npgsql Lead Developer
http://www.npgsql.org
http://gplus.to/franciscojunior
http://fxjr.blogspot.com
http://twitter.com/franciscojunior

Regards,

Francisco Figueiredo Jr.
Npgsql Lead Developer
http://www.npgsql.org
http://gplus.to/franciscojunior
http://fxjr.blogspot.com
http://twitter.com/franciscojunior

@roji
Copy link
Member

roji commented Feb 12, 2014

Not at all, Francisco, I think it's OK... It's only developers who run the unit tests and it's a reasonable requirement, especially since the tests actually test createdb capabilities... I'd say go for it.

@franciscojunior
Copy link
Member

Hi, @DavidKarlas ! I'm just configuring our database server to give permission to our tests user to create database so those new tests don't raise errors. As soon as I get that resolved, I'll merge your code. I think it is very good and will be an excellent addition to EF users! Thank you very much!

@DavidKarlas
Copy link
Contributor Author

Glad to hear that ;) I will keep watching issues on Github and resolve any problems with migrations ASAP when users find them. I hope you put some -Pre Nuget binary on soon :)

@franciscojunior
Copy link
Member

Great!
We are working in the 2.1.0 rc1 release and soon it will be a stable release.
Database migration is set to be part o fthe 2.2 release which will start to create betas very soon after 2.1 final is release. But I'm already talking about your pull request and asking users to give it a try: https://groups.google.com/forum/#!topic/npgsql-help/97X1QX5WE5k

I'll also write a blog post about this new feature so more people will start to use and test it! :)

@roji
Copy link
Member

roji commented Feb 17, 2014

A small note... Right now this PR doesn't compile for me (and the build server) because references point to EF6.0.2, but in the packages directory I can see EF6.0.1.

Can you confirm that you've switched to nuget "package restore" and this is why I'm not seeing EF6.0.2 in git? If so, the old EF6.0.1 needs to be deleted and I will enable package restore on our build server.

@DavidKarlas
Copy link
Contributor Author

Yes I switched to EF6.0.2.

  • Should I switch back to EF6.0.1 and let you do transition?
  • Should I delete packages/EntityFramework.6.0.1 in my pull request?
  • Should I delete packages/EntityFramework.6.0.1 and add packages/EntityFramework.6.0.2 in my pull request?
  • Or you was just asking to confirm and you will do what has to be done?

@roji
Copy link
Member

roji commented Feb 17, 2014

Yeah, unless you have a specific need for EF6.0.2 right now, please switch back to EF6.0.1 for now. After the PR is merged I'll take care of moving to EF6.0.2 with clean nuget package restore etc. Thanks.

@franciscojunior
Copy link
Member

I also think it is better to use the 6.0.1 version.

@DavidKarlas
Copy link
Contributor Author

Is this build server of yours a bit lazy? :P

@franciscojunior
Copy link
Member

On Mon, Feb 17, 2014 at 6:08 PM, David Karlaš notifications@github.comwrote:

Is this build server of yours a bit lazy? :P

:D

We didn't enable automatic build of pull requests yet. =)

Only merges are automatically being built.


Reply to this email directly or view it on GitHubhttps://github.com//pull/91#issuecomment-35323017
.

@franciscojunior
Copy link
Member

Hi, @DavidKarlas ! I'm still having problems compiling your changes even after you reverted to use EF 6.0.1. I'm checking what is happening and I will merge your changes when I get the builds going. Sorry for delay... :(

@franciscojunior
Copy link
Member

I think I got it! I tried a custom build where I do a clean checkout before the build and now it is compiling!

It was giving errors when trying to compile the EntityFrameworkTests as it couldn't find the EntityFramework.dll assembly.

@franciscojunior
Copy link
Member

Everything is almost ready. Compilation problem is now solved. Now I need to fix the permission of npgsql_tests user to be able to create database. I forgot to make this configuration change :)

Right now I'm at my job and the firewall here doesn't allow me connect to the build server to do this change. I'll make it later and then I hope everything will be ready to merge! :)

@DavidKarlas
Copy link
Contributor Author

Glad to hear this!

@franciscojunior
Copy link
Member

Hi, @DavidKarlas !

I just added the permission to create database to our tests user. Create database tests and a lot of others are passing ok.
Unfortunately, I'm still getting the following errors in the tests:

[NpgsqlTests.dll] NpgsqlTests.EntityFrameworkMigrationTests("8.4").TestCreateTableOperation
[20:04:25]
[NpgsqlTests.EntityFrameworkMigrationTests("8.4").TestCreateTableOperation] Test(s) failed.   Expected string length 38 but was 24. Strings differ at index 14.
  Expected: "CREATE SCHEMA IF NOT EXISTS someSchema"
  But was:  "CREATE SCHEMA someSchema"
  -------------------------^
[20:04:25]
[NpgsqlTests.EntityFrameworkMigrationTests("8.4").TestCreateTableOperation] Test(s) failed.   Expected string length 38 but was 24. Strings differ at index 14.
  Expected: "CREATE SCHEMA IF NOT EXISTS someSchema"
  But was:  "CREATE SCHEMA someSchema"
  -------------------------^

   at NUnit.Framework.Assert.That(Object actual, IResolveConstraint expression, String message, Object[] args)
   at NpgsqlTests.EntityFrameworkMigrationTests.TestCreateTableOperation()
[20:04:25][NpgsqlTests.dll] NpgsqlTests.EntityFrameworkMigrationTests("8.4").TestDefaultTypes
[20:04:25][NpgsqlTests.dll] NpgsqlTests.EntityFrameworkMigrationTests("8.4").TestDropColumnOperation
[20:04:25][NpgsqlTests.dll] NpgsqlTests.EntityFrameworkMigrationTests("8.4").TestDropForeignKeyOperation
[20:04:25]
[NpgsqlTests.EntityFrameworkMigrationTests("8.4").TestDropForeignKeyOperation] Test(s) failed.   Expected string length 58 but was 48. Strings differ at index 40.
  Expected: "ALTER TABLE "someTable" DROP CONSTRAINT IF EXISTS "someFK""
  But was:  "ALTER TABLE "someTable" DROP CONSTRAINT "someFK""
  ---------------------------------------------------^
[20:04:25]
[NpgsqlTests.EntityFrameworkMigrationTests("8.4").TestDropForeignKeyOperation] Test(s) failed.   Expected string length 58 but was 48. Strings differ at index 40.
  Expected: "ALTER TABLE "someTable" DROP CONSTRAINT IF EXISTS "someFK""
  But was:  "ALTER TABLE "someTable" DROP CONSTRAINT "someFK""
  ---------------------------------------------------^

   at NUnit.Framework.Assert.That(Object actual, IResolveConstraint expression, String message, Object[] args)
   at NpgsqlTests.EntityFrameworkMigrationTests.TestDropForeignKeyOperation()
[20:04:25][NpgsqlTests.dll] NpgsqlTests.EntityFrameworkMigrationTests("8.4").TestDropIndexOperation
[20:04:25][NpgsqlTests.dll] NpgsqlTests.EntityFrameworkMigrationTests("8.4").TestDropIndexOperationTableNameWithSchema
[20:04:25][NpgsqlTests.dll] NpgsqlTests.EntityFrameworkMigrationTests("8.4").TestDropPrimaryKeyOperation
[20:04:25][NpgsqlTests.dll] NpgsqlTests.EntityFrameworkMigrationTests("8.4").TestDropTableOperation
[20:04:25][NpgsqlTests.dll] NpgsqlTests.EntityFrameworkMigrationTests("8.4").TestHistoryOperation
[20:04:25][NpgsqlTests.dll] NpgsqlTests.EntityFrameworkMigrationTests("8.4").TestMoveTableOperation
[20:04:25]
[NpgsqlTests.EntityFrameworkMigrationTests("8.4").TestMoveTableOperation] Test(s) failed.   Expected string length 41 but was 27. Strings differ at index 14.
  Expected: "CREATE SCHEMA IF NOT EXISTS someNewSchema"
  But was:  "CREATE SCHEMA someNewSchema"
  -------------------------^
[20:04:25]
[NpgsqlTests.EntityFrameworkMigrationTests("8.4").TestMoveTableOperation] Test(s) failed.   Expected string length 41 but was 27. Strings differ at index 14.
  Expected: "CREATE SCHEMA IF NOT EXISTS someNewSchema"
  But was:  "CREATE SCHEMA someNewSchema"
  -------------------------^

   at NUnit.Framework.Assert.That(Object actual, IResolveConstraint expression, String message, Object[] args)
   at NpgsqlTests.EntityFrameworkMigrationTests.TestMoveTableOperation()
[20:04:25][NpgsqlTests.dll] NpgsqlTests.EntityFrameworkMigrationTests("8.4").TestMoveTableOperationNewSchemaIsNull
[20:04:25]
[NpgsqlTests.EntityFrameworkMigrationTests("8.4").TestMoveTableOperationNewSchemaIsNull] Test(s) failed.   Expected string length 31 but was 17. Strings differ at index 14.
  Expected: "CREATE SCHEMA IF NOT EXISTS dbo"
  But was:  "CREATE SCHEMA dbo"
  -------------------------^
[20:04:25]
[NpgsqlTests.EntityFrameworkMigrationTests("8.4").TestMoveTableOperationNewSchemaIsNull] Test(s) failed.   Expected string length 31 but was 17. Strings differ at index 14.
  Expected: "CREATE SCHEMA IF NOT EXISTS dbo"
  But was:  "CREATE SCHEMA dbo"
  -------------------------^

   at NUnit.Framework.Assert.That(Object actual, IResolveConstraint expression, String message, Object[] args)
   at NpgsqlTests.EntityFrameworkMigrationTests.TestMoveTableOperationNewSchemaIsNull()

I think server version checks need to be made inside the tests too just like the creation statements. :)

Those errors appear on all server versions tested (8.4, 9.0, 9.1 and 9.2) but 9.3

What do you think?

Other than that, everything seems to be going very well. :)

@franciscojunior
Copy link
Member

Hi, @DavidKarlas !
Running tests on our build server right now. So far, tests are passing smoothly!

@franciscojunior
Copy link
Member

We are almost there!

On .net 4.0 and 4.5 all tests pass ok.

EntityFrameworkBasicTests are failing on .net 3.5 and 2.0:

[NpgsqlTests.dll] NpgsqlTests.EntityFrameworkBasicTests("8.4")
[07:44:49][NpgsqlTests.EntityFrameworkBasicTests("8.4")] SetUp method failed. SetUp : System.InvalidOperationException : The Entity Framework provider type 'Npgsql.NpgsqlServices, Npgsql.EntityFramework' registered in the application config file for the ADO.NET provider with invariant name 'Npgsql' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
[07:44:49]
[NpgsqlTests.EntityFrameworkBasicTests("8.4")] SetUp method failed. SetUp : System.InvalidOperationException : The Entity Framework provider type 'Npgsql.NpgsqlServices, Npgsql.EntityFramework' registered in the application config file for the ADO.NET provider with invariant name 'Npgsql' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
   at System.Data.Entity.Infrastructure.DependencyResolution.ProviderServicesFactory.GetInstance(String providerTypeName, String providerInvariantName)
   at System.Data.Entity.Internal.AppConfig.<.ctor>b__2(ProviderElement e)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at System.Data.Entity.Internal.AppConfig.<.ctor>b__1()
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at System.Data.Entity.Internal.AppConfig.get_DbProviderServices()
   at System.Data.Entity.Infrastructure.DependencyResolution.AppConfigDependencyResolver.RegisterDbProviderServices()
   at System.Data.Entity.Infrastructure.DependencyResolution.AppConfigDependencyResolver.GetServiceFactory(Type type, String name)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at System.Data.Entity.Infrastructure.DependencyResolution.AppConfigDependencyResolver.GetService(Type type, Object key)
   at System.Data.Entity.Infrastructure.DependencyResolution.DbDependencyResolverExtensions.GetServiceAsServices(IDbDependencyResolver resolver, Type type, Object key)
   at System.Linq.Enumerable.<SelectManyIterator>d__14`2.MoveNext()
   at System.Linq.Enumerable.<ConcatIterator>d__71`1.MoveNext()
   at System.Linq.Enumerable.<OfTypeIterator>d__aa`1.MoveNext()
   at System.Data.Entity.Utilities.IEnumerableExtensions.Each[T](IEnumerable`1 ts, Action`1 action)
   at System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.<.ctor>b__1()
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.GetConfiguration()
   at System.Data.Entity.DbContext.InitializeLazyInternalContext(IInternalConnection internalConnection, DbCompiledModel model)
   at NpgsqlTests.EntityFrameworkBasicTests.TestFixtureSetup()

I think BasicTests are missing the #if NET40 like you did with MigrationTests.

@franciscojunior
Copy link
Member

Excellent work, David! All tests pass now! Merging now...

franciscojunior added a commit that referenced this pull request Feb 20, 2014
Support for EFMigration and Database creation
@franciscojunior franciscojunior merged commit 0cfe3b4 into npgsql:master Feb 20, 2014
@jgilm
Copy link

jgilm commented Apr 8, 2014

I hope I am not asking in the wrong place. I have built the master branch so that I could begin to use EF Migration support (excellent work BTW). Two things that I have noticed, but I'm not sure if I am doing something wrong.

First, all of my string entity properties are being rendered (when doing add-migration) as

c.String(maxLength: 1073741823, fixedLength: true)

which causes PostgreSQL/npgsql to throw an exception. I would like them to be either:

c.String(fixedLength: false)

or

c.String(storeType: "text")

Is there any way to default it to one of the above methods when doing an add-migration?

Second, it appears when one table depends upon another, in my example I have a "country" table and a "user" table that has a foreign key to "country.id". Again, when doing add-migration the migration works very well, but the tables being depended upon are listed after the tables that depend. In my example, the user table CreateTable is being called before the country CreateTable. It is easy to rearrange the order, but I was wondering if this was expected or if it is something that can be fixed?

@DavidKarlas
Copy link
Contributor Author

End goal here is that you don't care if you are targeting MS SQL or Postgresql so EVERYTHING must be fixed :) (Except stored procedures)

I would prefer if you could open two separate issues for this for better tracking and stuff...

It would also be awesome if you could copy-paste output of "Update-Database –Verbose" command where actual Postgresql commands are displayed ;)

Btw tnx for giving it a try ;)
I'm a bit busy atm so I will take deeper look into this when you open new issues if posible with that output... tnx

@phallett
Copy link

Hi,

I am trying to create an MVC web site using PostGreSQL with PostGIS. I simply can't get this configured and it's riving me slowly insane. I get the error:

Your project references the latest version of Entity Framework; however, an Entity Framework 3 database provider compatible with this version could not be found for your data connection. If you have already installed a compatible provider, ensure you have rebuilt your project before performing this action. Otherwise, exit this wizard, install a compatible provider, and rebuild your project before performing this action.

No matter what I do, after following all of the advice here, and obviously need an EDM to be able to autocomplete from the database. Using it with a connection string allows me to easily connect to teh database and select and display data, but obviously I want to use models and the EDM.

Any ideas? I'm rapidly balding here...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants