Type reloading doesn't occur when creating database in async mode
See original GitHub issueHello,
this is my moved issue from the EntityFrameworkCore repository about using spatial data with Postgresql. https://github.com/aspnet/EntityFrameworkCore/issues/12762
In order to locate the issue I created a single file which contains all the relevant code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using NetTopologySuite.Geometries;
using Xunit;
namespace EF.Demo.Test
{
public class GeometryTest
{
public class MyDbContext : DbContext
{
public DbSet<City> Cities { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder builder)
{
builder.UseNpgsql("Host=localhost;Database=test;Username=postgres;Password=mypassword",
o => o.UseNetTopologySuite());
}
protected override void OnModelCreating(ModelBuilder builder)
{
builder.HasPostgresExtension("postgis");
}
}
public class City
{
public int Id { get; set; }
public string Name { get; set; }
public Point Location { get; set; }
}
[Fact]
public async Task Test()
{
var loc = new Point(4.15, 51.51, 0) {SRID = 4326};
using (var ctx = new MyDbContext())
{
await ctx.Database.EnsureDeletedAsync();
await ctx.Database.EnsureCreatedAsync();
var city = new City()
{
Id = 1,
Name = "MyCity",
Location = loc
};
await ctx.Cities.AddAsync(city);
await ctx.SaveChangesAsync();
}
using (var ctx = new MyDbContext())
{
var city = await ctx.Cities.FindAsync(1);
Assert.NotNull(city?.Location);
Assert.True(loc.Distance(city.Location) < 0.000001);
}
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net461;netcoreapp2.1</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.1.1.1" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.NetTopologySuite" Version="2.1.1" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EF.Demo\EF.Demo.csproj" />
</ItemGroup>
</Project>
I receive the following error:
Microsoft.EntityFrameworkCore.DbUpdateException : An error occurred while updating the entries. See the inner exception for details.
---- Npgsql.NpgsqlException : The NpgsqlDbType 'Geometry' isn't present in your database. You may need to install an extension or upgrade to a newer version.
Issue Analytics
- State:
- Created 5 years ago
- Comments:17 (9 by maintainers)
Top Results From Across the Web
Asynchronous Database call to MySql Database gives error
{"The database type "MySqlDatabase" does not support asynchronous operations. "} Below is the complete stack image of the error..
Read more >Availability modes for an availability group - SQL Server ...
Learn the three different availability modes for an Always On availability group: asynchronous-commit mode, synchronous-commit mode, ...
Read more >Using Async, Await, and Task to keep the WinForms UI ...
Using the async/await pattern in WinForms is an easy win, helping prevent one of the most annoying user experiences - a frozen UI....
Read more >ModifyDBInstance - Amazon Relational Database Service
Specifies whether major version upgrades are allowed. Changing this parameter doesn't result in an outage and the change is asynchronously applied as soon...
Read more >Write asynchronous DAO queries
One-shot read queries that read data from your database only once and return a result with the snapshot of the database at that...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I appear to be having the same problem in Npgsql assembly version 5.0.3.0. In my case, my app will auto-migrate the DB on startup, which may create the database. The workaround of calling ReloadTypes() is working:
Creating a new DbContext would probably also have fixed it.
@Andrioden the fix hasn’t been released yet, so it makes sense for this error to still exist. We should try and get 2.1.4 out ASAP.