小编brs*_*tkr的帖子

M1相关!- Prisma:无法到达“数据库”处的数据库服务器:“5432”

自从我迁移到新的 Apple Silicon 架构后,我使用 nextjs 和 postgres 进行的 docker 设置就不再工作了。我使用prisma的nextjs服务器无法找到docker内的数据库。

prisma 客户端无法通过端口 5432 访问 postgres 数据库。

无法访问数据库服务器test-postgres5432

迁移也不起作用并返回上述相同的错误。

docker-compose run --publish 5555:5555 next npx prisma migrate dev
Run Code Online (Sandbox Code Playgroud)

docker-compose.yml

postgres:
    container_name: 'test-postgres'
    restart: unless-stopped
    image: 'postgres:13'
    ports:
      - '15432:5432'
    volumes:
      - 'pgdata:/var/lib/postgresql/data/'
    environment:
      POSTGRES_PASSWORD: postgres
Run Code Online (Sandbox Code Playgroud)

.env

DATABASE_URL="postgres://postgres:postgres@localhost:15432/postgres"
Run Code Online (Sandbox Code Playgroud)

我还将arm二进制目标添加到schema.prisma schema.prisma


generator client {
  provider        = "prisma-client-js"
  binaryTargets   = ["native", "debian-openssl-1.1.x", "linux-arm-openssl-1.1.x", "linux-musl"]
  previewFeatures = ["orderByRelation", "selectRelationCount"]
}
Run Code Online (Sandbox Code Playgroud)

postgres 容器实际上正在运行,我可以通过 Docker 桌面仪表板看到它。我在 postgres 容器内注意到的一件事是这个错误:

2021-07-21 12:52:58.927 UTC [76] ERROR:  relation …
Run Code Online (Sandbox Code Playgroud)

postgresql node.js docker prisma apple-m1

27
推荐指数
2
解决办法
3万
查看次数

如何在 Blazor WebAssembly-PWA 中运行离线数据库使用?

我有一个Blazor WebAssembly ASP.NET Core hosted - PWA应用程序,也想离线运行它。该数据库目前使用 SQLite 和 EF-Core 构建。是否可以添加离线功能?我已经阅读过IndexedDB但实际上并不知道如何将其实现到项目(客户端)中。或者是否有任何用于此支持的 NuGet 包?

我想带入项目的功能是 -跟踪本地更改并在再次联机时将它们提取到数据库。

c# indexeddb asp.net-core blazor blazor-client-side

6
推荐指数
2
解决办法
5433
查看次数

如何使用 xunit test 比较两个列表

我目前正在尝试使用 xUnit 比较两个列表,其中包含相同的项目,但在运行时出现错误。

Assert.Equal(expectedList, actualList);

Run Code Online (Sandbox Code Playgroud)

错误:

"Assert.Equal() Failure"
Expected: List<myObject> [myObject { modifier = '+', name = "name", type = "string" }, myObject { modifier = '+', name = "age", type = "int" }]
Actual:   List<myObject> [myObject { modifier = '+', name = "name", type = "string" }, myObject { modifier = '+', name = "age", type = "int" }]

Run Code Online (Sandbox Code Playgroud)

c# unit-testing list xunit

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

SQLite EF Core - 'FOREIGN KEY 约束失败'

在我的 ASP.Net Core 项目中,我在启动时遇到了这个异常,因为我正在运行时初始化数据库:

失败:Microsoft.EntityFrameworkCore.Update[10000]

保存上下文类型“BlazorWeb.Server.Data.SQLiteTestDbContext”的更改时,数据库中发生异常。
Microsoft.EntityFrameworkCore.DbUpdateException:更新条目时出错。有关详细信息,请参阅内部异常。

Microsoft.Data.Sqlite.SqliteException (0x80004005):SQLite 错误 19:“外键约束失败”。

在 Microsoft.Data.Sqlite.SqliteException.ThrowExceptionForRC(Int32 rc, sqlite3 db)
....

我的模型:

public class ObjectModel : BaseEntity
{
    [Key]
    public int Id { get; set; }
    public String Name { get; set; }
    public String PreviewImage { get; set; }
    public String  TagName { get; set; }

    // Foreign keys---
    public int TypeId { get; set; }
    public ObjectTypeModel TypeModel { get; set; }
    //---
}

public class ObjectTypeModel : BaseEntity
{
    [Key]
    public …
Run Code Online (Sandbox Code Playgroud)

c# sqlite entity-framework-core asp.net-core

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

Blazor WebAssembly 401 即使我已获得授权也未获得授权

我正在使用Blazor WebAssembly Asp.Net Core hosted PWA并将其集成AspNetCore.Identity到其中。我AuthenticationStateProvider在客户端创建了 ,现在我想允许用户访问需要授权的控制器。

我已经通过邮递员进行了测试,用户已aspnetusers使用正确的凭据创建并存储在数据库中。登录/帐户控制器按我想要的方式工作。

当用户被授权时,它会在访问授权控制器请求时在浏览器中告知此异常:

Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] 渲染组件未处理的异常:响应状态代码不指示成功:401(未经授权)。System.Net.Http.HttpRequestException:响应状态代码不指示成功:401(未经授权)。

Startup.cs(ConfigureServices-方法):

...
    serviceCollection.AddDbContext<SQLiteTestDbContext>(options =>
                {
                    options.UseSqlite(config["ConnectionStrings:SQLiteTestConnection"]);
                });
                serviceCollection.AddDefaultIdentity<IdentityUser>()
                    .AddEntityFrameworkStores<SQLiteTestDbContext>()
                    .AddDefaultTokenProviders();

    services.AddAuthentication(x =>
                    {
                        x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                    })
                    .AddJwtBearer(options =>
                    {
                        options.TokenValidationParameters = new TokenValidationParameters
                        {
                            ValidateIssuer = true,
                            ValidateAudience = true,
                            ValidateLifetime = true,
                            ValidateIssuerSigningKey = true,
                            ValidIssuer = Configuration["JwtIssuer"],
                            ValidAudience = Configuration["JwtAudience"],
                            IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["JwtSecurityKey"]))
                        };
                    });

    services.AddHttpContextAccessor();
                services.Configure<IdentityOptions>(options =>
                    options.ClaimsIdentity.UserIdClaimType = ClaimTypes.NameIdentifier);
...

 

    public void Configure(IApplicationBuilder …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-identity asp.net-core blazor blazor-webassembly

3
推荐指数
1
解决办法
8892
查看次数

C# 如何比较 Equals() 方法中的两个对象列表

我有两个具有相同元素和值的对象列表:

parameters = new List<Parameter>() { new Parameter() { parameterName="value", parameterType="string"} }
Run Code Online (Sandbox Code Playgroud)

参数类如下所示:

 public class Parameter
    {
        public string parameterName;

        public string parameterType;
    }
Run Code Online (Sandbox Code Playgroud)

我想通过单元测试将其与具有相同元素和值的相同对象列表进行比较。

我的方法类(我在方法对象之前创建,它存储了参数对象列表):

public class Method
{
   public List<Parameter> parameters { get; set;}

   public string modifier { get; set; }

   public string name { get; set; }

   public string type { get; set; }


   public override bool Equals(object obj)
        {
            return this.modifier == ((Method)obj).modifier && this.name == ((Method)obj).name && this.type == ((Method)obj).type
                && this.parameters == ((Method)obj).parameters; 
        } …
Run Code Online (Sandbox Code Playgroud)

c# unit-testing list equals object

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