标签: npgsql

如何从postgresql数据库生成edmx

我在postgresql中有一个数据库,我想在我的项目中使用vs 2010(v4.0)中的向导生成edmx(实体框架).

我按照本博客http://fxjr.blogspot.in/2011/05/npgsql-design-time-support-preview.html中给出的所有步骤进行了操作, 但在生成edmx时我找不到postgresql的数据提供程序.

我也见过http://ud-csharp.blogspot.in/2010/02/entity-framework-con-postgresql.html,但没有取得任何成功.

.net entity-framework npgsql asp.net-mvc-3

5
推荐指数
1
解决办法
3590
查看次数

无法确定类型为“Npgsql.NpgsqlFactory”的提供者工厂的提供者名称

我尝试运行一个测试项目,但我没有成功,因为 npgsql 连接失败。我重新安装了 Npgsql、Npgsql.EntityFramework、EntityFramwork ......但问题仍然存在。结果信息:

测试方法 TestUserControl.ControleBaseTest.TesteGetPermissoesUsuarioFixo gerou exceção:

System.NotSupportedException:无法确定类型为“Npgsql.NpgsqlFactory”的提供程序工厂的提供程序名称。确保在应用程序配置中安装或注册了 ADO.NET 提供程序。结果堆栈跟踪:

我有这个 app.config 文件:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <entityFramework>
    <providers>
      <provider invariantName="System.Data.SqlClient"     type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
      <provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, Npgsql.EntityFramework">    </provider>
    </providers>
    <!--<defaultConnectionFactory type="Npgsql.NpgsqlFactory, Npgsql" />-->
    <defaultConnectionFactory type="Npgsql.NpgsqlConnectionFactory, Npgsql" />
  </entityFramework>
  <system.data>
    <DbProviderFactories>
      <remove invariant="Npgsql" /> …
Run Code Online (Sandbox Code Playgroud)

c# postgresql asp.net-mvc unit-testing npgsql

5
推荐指数
1
解决办法
3342
查看次数

“错误:57014:由于用户请求而取消语句”Npgsql

我在我的应用程序中遇到了这个幻象问题,其中特定页面(在 ASP.NET MVC 应用程序上)上的每 5 个请求中就有一个抛出此错误:

Npgsql.NpgsqlException: ERROR: 57014: canceling statement due to user request
   at Npgsql.NpgsqlState.<ProcessBackendResponses>d__0.MoveNext()
   at Npgsql.ForwardsOnlyDataReader.GetNextResponseObject(Boolean cleanup)
   at Npgsql.ForwardsOnlyDataReader.GetNextRow(Boolean clearPending)
   at Npgsql.ForwardsOnlyDataReader.Read()
   at Npgsql.NpgsqlCommand.GetReader(CommandBehavior cb)
   ...
Run Code Online (Sandbox Code Playgroud)

在 npgsql github 页面上,我发现了以下错误报告:615

它在那里说:

不管 Dapper 到底发生了什么,在取消命令时肯定存在竞争条件。部分原因是设计使然,因为 PostgreSQL:取消请求是完全“异步的”(它们通过不相关的套接字传递,而不是作为要取消的连接的一部分),并且您不能限制取消生效仅在特定命令上。换句话说,如果您想取消命令 A,则在您发送取消时,命令 B 可能已经在进行中,它将被取消。

尽管他们在 Npgsql 3.0.2 中进行“希望使取消更安全的更改”,但我当前的代码与此版本不兼容,因为这里描述了迁移的需要。

我目前的解决方法(愚蠢):我已经评论了 Dapper 中的代码,command.Cancel();问题似乎消失了。

if (reader != null)
                {
                    if (!reader.IsClosed && command != null)
                    {
                        //command.Cancel();
                    }
                    reader.Dispose();
                    reader = null;
                }
Run Code Online (Sandbox Code Playgroud)

有没有更好的解决问题的方法?其次,我在当前修复中丢失了什么(除了每次更新 …

postgresql command npgsql dapper

5
推荐指数
1
解决办法
1万
查看次数

PostgreSQL,Npgsql 返回 42601:“$1”处或附近的语法错误

我正在尝试使用 Npgsql 和/或 Dapper 来查询表,但我一直遇到 Npgsql.PostgresException 42601: syntax error at or near "$1".

这是我使用 NpgsqlCommand 进行的尝试:

  using (var conn = new NpgsqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["postgres"].ConnectionString))
  {
    conn.Open();
    using (NpgsqlCommand command = new NpgsqlCommand("select * from Logs.Logs where Log_Date > current_date - interval @days day;", conn))
    {
      command.Parameters.AddWithValue("@days", days);
      var reader = command.ExecuteReader();
Run Code Online (Sandbox Code Playgroud)

我也用 Dapper(我的首选方法)尝试过:

  using (var conn = new NpgsqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["postgres"].ConnectionString))
  {
    conn.Open();
    var logs = conn.Query<Log>("select * from Logs.Logs where Log_Date > current_date - interval @days day;", new {days = days});
Run Code Online (Sandbox Code Playgroud)

无论哪种方式,我都会得到相同Npgsql.PostgresException …

postgresql npgsql dapper

5
推荐指数
2
解决办法
1万
查看次数

Npgsql / EF 6 - json 列

我正在尝试使用 JSON 列创建迁移。这是我尝试过的:

    [Column(TypeName = "Jsonb")]
    public string Data { get; set; }

    [Column(TypeName = "Json")]
    public string Data { get; set; }

    modelBuilder.Entity<Member>().Property(p => p.Data).HasColumnType("Json");

    modelBuilder.Entity<Member>().Property(p => p.Data).HasColumnType("Jsonb");
Run Code Online (Sandbox Code Playgroud)

什么都不起作用,这是例外:

System.InvalidOperationException: Sequence 在 System.Linq.Enumerable.Single[TSource](IEnumerable1 source, Func2 谓词) at System.Data.Entity.Utilities.DbProviderManifestExtensions.GetStoreTypeFromName(DbProviderManifest providerManifest, String name) at System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration.ConfigureColumn(EdmProperty column, EntityType table, DbestProviderManifest providerManifest在 System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration.Configure(EdmProperty 列,EntityType 表,DbProviderManifest providerManifest,Boolean allowOverride,Boolean fillFromExistingConfiguration)在 System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration .<>c__DisplayClass4.b__3(Tuple 2 pm) at System.Data.Entity.Utilities.IEnumerableExtensions.Each[T](IEnumerable1 ts, Action1 action) at System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration.Configure(IEnumerable1 propertyMappings, DbProviderManifest providerManifest, Boolean allowOverride, Boolean fillFromExistingConfiguration) at System.Data.Entity.ModelConfiguration.Configuration.Types.StructuralTypeConfiguration.ConfigurePropertyMappings(IList …

c# asp.net-mvc entity-framework npgsql entity-framework-migrations

5
推荐指数
1
解决办法
1423
查看次数

如何从 Npgsql 异常中判断该调用是否值得重试(瞬态故障策略)

我正在编写一个将连接到远程 postgres 服务器的服务。我正在寻找一种好方法来确定应将哪些异常视为瞬态(值得重试),以及如何定义适当的策略以连接到远程数据库。

该服务使用 Npgsql 进行数据访问。文档说 Npgsql 将抛出一个 PostgresException 的 sql 错误和一个 NpgsqlException 的“服务器相关问题”。

到目前为止,我能想到的最好的方法是假设所有不是 PostgresExceptions 的异常都应该被视为可能是暂时的,值得重试,但是 PostgresException 意味着查询有问题,重试无济于事. 我在这个假设中正确吗?

我正在使用 Polly 创建重试和断路器策略。因此,我的政策是这样的:

Policy.Handle<Exception>( AllButPotgresExceptions()) // if its a postgres exception we know its not going to work even with a retry, so don't
                       .WaitAndRetryAsync(new[]
                       {
                           TimeSpan.FromSeconds(1),
                           TimeSpan.FromSeconds(2),
                           TimeSpan.FromSeconds(4)
                       }, onRetry: (exception, span) => Log.Warning(exception, "Postgres Retry Failure: "))
                    .WrapAsync(
                           Policy.Handle<Exception>( AllButPotgresExceptions())
                               .AdvancedCircuitBreakerAsync(
                                   failureThreshold:.7, 
                                   samplingDuration: TimeSpan.FromSeconds(30), 
                                   minimumThroughput: 20, 
                                   durationOfBreak: TimeSpan.FromSeconds(30), 
                                   onBreak: (ex, timeSpan, context) => Log.Warning(ex, "Postres Circuit Breaker Broken: …
Run Code Online (Sandbox Code Playgroud)

c# postgresql npgsql microservices polly

5
推荐指数
1
解决办法
2315
查看次数

EF6 + npgsql + CodeFirst 不适用于几何

我们正在尝试将 EF6 + CodeFirst 与 PostGIS 数据库一起使用。

PostgreSQL v9.3.10
PostGIS v2.1.3
npgsql v3.2.2.0
EntityFramework6.Npgsql v3.1.1.0
Run Code Online (Sandbox Code Playgroud)

我没有几何图形的简单模型可以正常工作,Add-Migrations但是当我添加DbGeometry属性时Add-Migrations失败

Not supported edm type: Edm.Geometry
at Npgsql.NpgsqlProviderManifest.GetStoreType(TypeUsage edmType)
at System.Data.Entity.ModelConfiguration.Edm.Services.StructuralTypeMappingGenerator.MapTableColumn(EdmProperty property, String columnName, Boolean isInstancePropertyOnDerivedType)
Run Code Online (Sandbox Code Playgroud)

谷歌搜索我在 npgsql 的 GitHub 上找到了这些帖子:https : //github.com/npgsql/npgsql/issues/623https://github.com/npgsql/EntityFramework6.Npgsql/issues/18

这些帖子是 2015 年 5 月的。我无法想象还没有人找到解决这个问题的方法。我们不能成为多年来第一个EF6+CodeFirstPostGIS.

因此,请建议如何继续或建议其他正在运行的提供商。

postgis npgsql entity-framework-6 entity-framework-migrations

5
推荐指数
0
解决办法
563
查看次数

如何在 ASP.NET Boilerplate Core 2.0 模板中使用 Npgsql?

我花了很多时间尝试将 PostgreSQL 与 ASP.NET Boilerplate Core 2.x + Module Zero(看起来很棒!)一起使用。

  1. 我将Npgsql.EntityFrameworkCore.PostgreSQL&Npgsql.EntityFrameworkCore.PostgreSQL.Design依赖添加到myApp.EntityFrameworkCore.

  2. 我还更改了连接字符串,我使用builder.UseNpgsql而不是builder.UseSqlServerin myappDbContextConfigurer.cs

作为一个新项目,我从Npgsql v2.0.0. 但是经过几个问题,我发现这个版本有一些问题。所以我回到了1.1.1发布。

我很确定这部分工作正常。下一步是删除所有现有迁移并重新加载它们:

  • Add-Migration "Initial_Migrations"
  • Add-Migration "AbpZero_Initial"

当我做第一个时,我收到一个错误:

来自程序集“Npgsql.EntityFrameworkCore.PostgreSQL, Version=1.1.1.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7”的“Microsoft.EntityFrameworkCore.Infrastructure.Internal.NpgsqlOptionsExtension”类型中的方法“Clone”没有实现。

我在这里找到了解决方案的开始(第 6 篇文章):https : //forum.aspnetboilerplate.com/viewtopic.php?t=5304&p=13013

帖子似乎有点过时,我不知道在哪里实施NpgsqlMigrationSqlGenerator(我的意思是,在哪个项目中)。

感谢您阅读这篇文章,任何帮助将不胜感激。

migration postgresql npgsql aspnetboilerplate asp.net-core-2.0

5
推荐指数
1
解决办法
2111
查看次数

AspNetCore.Identity 使用 PostgreSQL:如何创建结构?

我有一个带有 AspNetCore.Identity Logins 的 ASP.NET Core Web 应用程序。它使用 SQL Server 进行用户身份验证。

我需要使用 PostgreSQL 数据库我添加了一些 nuget 包(EF.* 等),更改了连接字符串和代码

 public void ConfigureServices(IServiceCollection services)
        {
            services.Configure<CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded = context => true;
            });
//                options.UseSqlServer( Configuration.GetConnectionString("DefaultConnection")));
            services.AddDbContext<ApplicationDbContext>(options =>
                options.UseNpgsql( Configuration.GetConnectionString("DefaultConnection")));

            services.AddDefaultIdentity<IdentityUser>()
                .AddEntityFrameworkStores<ApplicationDbContext>();

            services.AddControllersWithViews()
                .AddNewtonsoftJson();
            services.AddRazorPages();
        }
Run Code Online (Sandbox Code Playgroud)

但是当我运行它时,它连接到 PostgreSQL 数据库并尝试创建我收到错误的结构,有什么问题?为什么EF不能创建结构?如何解决这个问题呢?

  Executing endpoint 'WebApplication1.Controllers.HomeController.Index (WebA
pplication1)'
info: Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker[3]
      Route matched with {action = "Index", controller = "Home", page …
Run Code Online (Sandbox Code Playgroud)

postgresql npgsql asp.net-core

5
推荐指数
2
解决办法
5583
查看次数

无法在 .NET Core 3.0 中使用 AssemblyLoadContext 加载插件依赖项

我有一个依赖项失败的插件,尽管我试图在 .NET Core 3.0 上遵循尽可能多的 MS 建议。2 天来一直试图找出问题所在:/。欣赏输入或查看位置。谢谢!

细节:

  • 入口点是 .NET Core 3.0 自包含应用程序发布的 CLI 应用程序
    //publishes as EXE file
    dotnet publish -c release -r win-x64 /p:publishsinglefile=true /p:publishtrimmed=true
    
    Run Code Online (Sandbox Code Playgroud)
  • 在 Win-x64 和 Linux-x64 上测试
  • .NET Core 3.0 程序集
  • 使用此命令发布插件 DLL

    //publishes as DLL files
    dotnet publish -c release -r linux-x64 /p:publishtrimmed=true -o ./app
    
    Run Code Online (Sandbox Code Playgroud)

日志显示文件在那里,它存在但依赖解析器无法加载它并抛出 FileNotFoundException。奇怪的。


C:\play\yuniql\yuniql-cli\bin\release\netcoreapp3.0\win-x64\publish>yuniql.exe run --plugins-path C:\temp\aztools\yuniql\0.0.0\x64\.plugins -p C:\play\yuniql\yuniql-plugins\postgresql\samples -c "Host=localhost;Port=5432;Username=xxx;Password=xxx;Database=yuniqldb" --platform postgresql -a 1 --debug
...
DBG   platformLowerCased: postgresql
DBG   pluginsPathParameter: C:\temp\aztools\yuniql\0.0.0\x64\.plugins
DBG   defaultAssemblyBasePath: C:\temp\aztools\yuniql\0.0.0\x64\.plugins\postgresql
...
DBG   Found …
Run Code Online (Sandbox Code Playgroud)

c# npgsql .net-core .net-core-3.0

5
推荐指数
0
解决办法
877
查看次数