小编han*_*shi的帖子

如何在 EF Core 6.0 中表示日期时间 - 没有时区的时间戳

我将 ASP.NET Core 项目从 3.1 迁移到 6.0。

我已复制旧迁移并将其粘贴到我们的新版本中

EF Core 3.1(旧)上的迁移

migrationBuilder.AddColumn<DateTime>(
                name: "CalendarStartDate",
                table: "DealOverview",
                nullable: false,
                defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
Run Code Online (Sandbox Code Playgroud)

EF Core 6.0 中的迁移(新)

migrationBuilder.AlterColumn<DateTime>(
                name: "StartDate",
                table: "DealOverview",
                type: "timestamp without time zone",
                nullable: false,
                oldClrType: typeof(DateTime),
                oldType: "timestamp with time zone");
Run Code Online (Sandbox Code Playgroud)

迁移失败,因为这一行

public DateTime StartDate { get; set; }
Run Code Online (Sandbox Code Playgroud)

已经改变。

我从这个包中走了出来:

<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.4" />
Run Code Online (Sandbox Code Playgroud)

到这个包:

<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.1" /> 
Run Code Online (Sandbox Code Playgroud)

c# postgresql entity-framework-core asp.net-core asp.net-core-6.0

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

我可以在CQRS中的另一个CommandHandler中调用QueryHandler/CommandHandler吗

我正在开发一个 ASP.NET Core 6.0 Web API 项目。我使用 CQRS 设计模式。

我想更新一个airlines表(代码优先 EF Core)。所以首先我需要找到航空公司的ID。

我有GetAirlineByIdQueryHandler.cs

public record GetAirlineByIdQuery(int Id, bool LoadOverview = true) : IRequest<Airline>;

public class GetAirlineByIdQueryHandler : IRequestHandler<GetAirlineByIdQuery, Airline>
{
    public async Task<Airline> Handle(GetAirlineByIdQuery request, CancellationToken cancellationToken)
    {
        var query = _techneDbContext.Airline
                .Include(d => d.X)
                .Include(d => d.Y)
                .Include(d => d.Z)
               
                .AsQueryable();

        if (request.LoadOverview)
        {
            query = query.Include(d => d.Overview);
        }

      var airline = await query.FirstOrDefaultAsync(d => d.Id == request.Id);


        if (airline == null)
        {
            throw new …
Run Code Online (Sandbox Code Playgroud)

c# cqrs asp.net-core asp.net-core-webapi

7
推荐指数
1
解决办法
4833
查看次数

在干净架构asp.net core中使用ApplicationUser时出现问题:IdentityUser、UserManager

我正在一个干净的架构中工作 asp.net core 6.0 WebAPI。https://github.com/jasontaylordev/CleanArchitecture

该架构中有 4 个项目。WebApi、基础设施、应用程序和域。

  • 领域是核心。
  • 应用层依赖于域层。
  • 基础设施层依赖于应用层。
  • WebApi 层依赖于应用层和基础设施层。

查询和命令(CQRS)应该写在应用层内部

我想使用 Asp.Net Core Identity。

ApplicationUser.cs(在基础设施/身份中)

namespace Infrastructure.Identity;

public class ApplicationUser : IdentityUser
{
  // removed
}
Run Code Online (Sandbox Code Playgroud)

IIdentityService.cs(在应用程序/公共/接口中)

namespace Application.Common.Interfaces;

public interface IIdentityService
{
    Task<string> GetUserNameAsync(string userId);

    Task<bool> IsInRoleAsync(string userId, string role);

    Task<bool> AuthorizeAsync(string userId, string policyName);

    Task<(Result Result, string UserId)> CreateUserAsync(string userName, string password);

    Task<Result> DeleteUserAsync(string userId);

   // and so on
}
Run Code Online (Sandbox Code Playgroud)

IdentityService.cs(在基础设施/身份中)

namespace Infrastructure.Identity;

public class IdentityService : IIdentityService
{
    private readonly UserManager<ApplicationUser> _userManager;

    public …
Run Code Online (Sandbox Code Playgroud)

c# asp.net asp.net-identity asp.net-core clean-architecture

6
推荐指数
1
解决办法
2605
查看次数

将值“02:30:40”转换为类型“System.TimeOnly”时出错

我正在开发一个 .net6.0 项目(使用 postgreSql)

我想将办公室的开始时间和下班时间保存到数据库中。

我这样做了。

public class WorkingDay
{
    public int Id { get; set; }

    public DaysOfWeek Day { get; set; }  // enum

    public OpeningHours OpeningHours { get; set; }

    public bool IsworkingDay { get; set; }
}


public class OpeningHours
{
    public TimeOnly StartTime { get; set; }

    public TimeOnly OffTime { get; set; }

}

Run Code Online (Sandbox Code Playgroud)

现在我使用 POSTMAN 发送要创建的数据。

{
    "Day" : 1,
    "OpeningHours" : {
        "StartTime":  "02:30:40", 
        "OffTime" :  "02:30:40"
    },
    "IsworkingDay" : false
} …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-core .net-6.0

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

无法找到任何已安装的 .NET SDK

我已经安装了多个版本的 .NET Sdk。现在 Omnisharp 建议无法正常工作。

输出显示这些

[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: /BO-V2/Techne-Travel/travel-techne-bo-for-ota/src/Application/Application.csproj
A compatible installed .NET SDK for global.json version [6.0.101] from [/BO-V2/Techne-Travel/travel-techne-bo-for-ota/global.json] was not found.
Install the [6.0.101] .NET SDK or update [/BO-V2/Techne-Travel/travel-techne-bo-for-ota/global.json] with an installed .NET SDK:
  It was not possible to find any installed .NET SDKs.
Install a .NET SDK from:
  https://aka.ms/dotnet-download
A compatible installed .NET SDK for global.json version [6.0.101] from [/BO-V2/Techne-Travel/travel-techne-bo-for-ota/global.json] was not found.
Install the [6.0.101] .NET SDK or update [/BO-V2/Techne-Travel/travel-techne-bo-for-ota/global.json] with an installed .NET …
Run Code Online (Sandbox Code Playgroud)

c# asp.net omnisharp visual-studio-code asp.net-core

0
推荐指数
1
解决办法
2254
查看次数