小编Rey*_*gle的帖子

创建流畅的API

如何创建一个流畅的API?

这主要使用扩展方法吗?

c# fluent

53
推荐指数
6
解决办法
4万
查看次数

MongoDB过去一小时的日期范围查询

我正在尝试编写MongoDB查询,它将在一小时前返回数据.有一个time带有timestamps("time" : NumberLong("1471953787012"))的列,这就是它在SQL中的样子:

select name from table
where time between (NOW() - INTERVAL 1 HOUR) AND (NOW())
Run Code Online (Sandbox Code Playgroud)

如何编写MongoDB查询以查找一小时前的日期范围?我正在尝试新的Date()函数,但它不起作用.有谁知道我做错了什么?

db.coll.find({ 
  "time" : { 
    $lt: new Date(), 
    $gte: new Date(new Date().setDate(new Date().getDate()-1))
  }   
})
Run Code Online (Sandbox Code Playgroud)

datetime mongodb mongodb-query

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

在SQL Server中查找派生表的记录计数

CREATE  TABLE   Temp
(
   ID   Int IDENTITY,
   Name Varchar(100)
)

INSERT  INTO    Temp
SELECT  'Elby'
UNION ALL
SELECT  'Eljo'
UNION ALL
SELECT  'Elsy'
UNION ALL
SELECT  'Elsy'
UNION ALL
SELECT  'Eljo'
UNION ALL
SELECT  'Elsy'
UNION ALL
SELECT  'Elsy'
Run Code Online (Sandbox Code Playgroud)

我要求的输出是..

    ----------------------------------------
    TotalRecordCount        ID      Name
    ----------------------------------------
    7                       5       Elby
    7                       6       Eljo
    7                       7       Elsy
    7                       8       Elsy
    ----------------------------------------    
Run Code Online (Sandbox Code Playgroud)

我的查询是...

SELECT  TotalRecordCount,
        ID,
        Name        
FROM    (
        SELECT  *
        FROM    Temp
      ) Tab1
WHERE   ID > 4
Run Code Online (Sandbox Code Playgroud)

我的问题是,如何找到“ TotalRecordCount”字段的值。它是表“ Temp”的总数。

我不能使用像' SELECT …

sql sql-server

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

带有子路由的 Angular 将子组件加载到父组件下面,而不是将其重定向到另一个视图

我有一个 MuscleComponent,其中有 MuscleAddComponent 和 MuscleEditComponent 作为其子组件。当我单击子组件时,我试图重定向到它们,但它们却出现在 MuscleComponent 的同一视图上。

注意:当我{ path: '', component: MusclesComponent, pathMatch: 'full' },在肌肉路径的子级中时,我在同一页面上得到两个相同外观的 MuscleComponent 的 html。为什么会这样呢?为什么当我单击“添加”按钮时,它会在 MuscleComponent 的 html 上显示 MuscleAddComponent 的内容?

应用程序路由.module.ts

const routes: Routes = [
  { path: '', component: HomeComponent, pathMatch: 'full' },
  {
    path: 'muscles', component: MusclesComponent, children: [
      { path: '', component: MusclesComponent, pathMatch: 'full' },
      { path: 'add', component: MuscleAddComponent },
      { path: ':id', component: MuscleEditComponent }
    ]
  },
  { path: 'workouts', component: WorkoutsComponent },
  { path: 'myplanner', component: …
Run Code Online (Sandbox Code Playgroud)

angular2-routing angular

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

Asp.Net Azure Cloud - 获取文件大小需要很长时间

我想获得父文件夹下可用的各种子文件夹下所有文件的大小总和。

我得到了大小,但计算结果大约需要 15 秒。

这是代码:

var storageAccount = CloudStorageAccount.Parse("connectionString");
var fileClient = storageAccount.CreateCloudFileClient();
var cloudFileShare = fileClient.GetShareReference("shareName");
var rootDirectory = cloudFileShare.GetRootDirectoryReference();
var directory = rootDirectory.GetDirectoryReference("folderName");

var size = directory.ListFilesAndDirectories().Select(x => (CloudFileDirectory)x).SelectMany(x => x.ListFilesAndDirectories()).Sum(x => ((CloudFile)x).Properties.Length);
Run Code Online (Sandbox Code Playgroud)

我可以进一步优化它以快速获得尺寸吗?

编辑1:

测试:

  • 场景 1:包含更多或更少文件的更多文件夹
  • 场景 2:文件夹更少,文件更多或更少

发现:

  • 无论文件数量如何(可能更多或更少),当文件夹数更多时需要很长时间
  • 当文件夹数量较少时,它工作正常,而不管文件数量(可能更多或更少)

.net c# cloud azure

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

.Net Core - 具有多个身份验证服务器的身份服务器

我有 4 个身份验证服务器,用于验证我的应用程序上传入请求的令牌。

我有以下ConfigureServices配置Startup.cs

services.AddAuthentication()
    .AddJwtBearer("authServer1", options =>
     {
         options.Authority = "https://authserver1.com/AuthServices/Auth";
         options.Audience = "web.api";
     })
    .AddJwtBearer("authServer2", options =>
    {
        options.Authority = "https://authserver2.com/AuthServices/Auth";
        options.Audience = "web.api";
    })
    .AddJwtBearer("authServer3", options =>
    {
        options.Authority = "https://authserver3.com/AuthServices/Auth";
        options.Audience = "web.api";
    })
    .AddJwtBearer("authServer4", options =>
    {
        options.Authority = "https://authserver4.com/AuthServices/Auth";
        options.Audience = "web.api";
    });

services.AddAuthorization(options =>
    {
        options.DefaultPolicy = new AuthorizationPolicyBuilder()
            .RequireAuthenticatedUser()
            .AddAuthenticationSchemes("authServer1", "authServer2", "authServer3", "authServer4")
            .Build();
    });
Run Code Online (Sandbox Code Playgroud)

当我调用 API 时,它工作正常。

问题是假设任何身份验证服务器出现故障,并且我尝试调用 API,然后应用程序会给出错误,指出未找到特定的身份验证服务器或任何特定于该情况的错误。

1)如何跳过任何身份验证服务器出现故障时可能发生的错误?

2)在选择相应的身份验证服务器来验证传入请求时,策略如何工作?它的工作方式是否像 switch case(直接跳转到相应的身份验证服务器)或 if-elseladder(检查每个身份验证服务器的请求验证,直到找到实际的服务器)

jwt asp.net-core identityserver4

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

为 LINQ 查询使用表达式树构建 Any()

我正在使用 System.Linq.Expressions.Expression 类动态构建 SQL“Any”子句

我可以这样做

Expression<Func<User, Lead, bool>> predicate = (user, lead) => user.UserRoleSubProducts.Any(x => x.SubProductID == lead.SubProductID);
Run Code Online (Sandbox Code Playgroud)

但是我无法使用表达式树来实现这一点。

我在下面试过

var param1 = Expression.Parameter(typeof(User), "user");
var property1 = Expression.Property(param1, "UserRoleSubProducts");
var exp1 = Expression.Lambda(property1, new[] { param1 });

var param2 = Expression.Parameter(typeof(Lead), "lead");
var property2 = Expression.Property(param2, "SubProductID");
var exp2 = Expression.Lambda(property2, new[] { param2 });

var param3 = Expression.Parameter(property1.Type.GetProperty("Item").PropertyType, "x");
var property3 = Expression.Property(param3, "SubProductID");
var exp3 = Expression.Lambda(property3, new[] { param3 });

var equality = Expression.Equal(property2, property3);

var …
Run Code Online (Sandbox Code Playgroud)

c# linq expression-trees

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

在 Linux 中将 WordPress 升级到最新版本

除了传统方式之外,还有什么方法可以轻松地将 WordPress 升级到 Linux 中的最新版本吗?

linux wordpress command upgrade

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

C# - 生成内存中的数据库备份脚本

在 C# 应用程序中,我知道使用 ADO.NET 我们可以执行如下备份命令:

BACKUP DATABASE MyDb TO DISK='C:\\MyDb.bak'
Run Code Online (Sandbox Code Playgroud)

并进行数据库备份并将其存储在某个给定位置。

我想备份内存中的数据库,即返回备份脚本内容(架构和数据),稍后我可以将其保存为.sql文件在某个位置。

这可能吗?

c# sql-server asp.net asp.net-mvc

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