小编Onk*_*oob的帖子

Angular:事件和"订阅不是函数"错误

大家好,感谢您阅读本文.

我刚刚开始深入研究一些基本的Angular 4,并且我很难听到发出的事件.这是一个非常简单的例子,可以重现问题(至少在我的最后):

DateSenderComponent是"广播"当前日期,然后由其母公司处理AppComponent(见下文):

import { Component, Output } from '@angular/core';
import { EventEmitter } from "events";

@Component({
  selector: 'app-date-sender',
  template: '<button (click)="sendDate()">Send</button>'
})

export class DateSenderComponent {
  @Output() dateSent = new EventEmitter();

  sendDate(){
    var dt = new Date();
    console.log(dt);
    this.dateSent.emit(dt.toString());
  }
}
Run Code Online (Sandbox Code Playgroud)

AppComponent 应该听广播的日期事件:

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  template: '<app-date-sender (dateSent)="dateReceived($event)"></app-date-sender>'
})

export class AppComponent {
  dateReceived(value){
    console.log('Result: ', value);
  }
}
Run Code Online (Sandbox Code Playgroud)

从各种初学者教程中我发现这是听取事件的方式.但是,加载页面时,我得到以下错误,而不是打印出收到的日期值:

AppComponent.html:1 ERROR TypeError:instance [output.propName] .subscribe不是函数

在createDirectiveInstance(core.es5.js:10727)

在createViewNodes(core.es5.js:12086)

在callViewAction(core.es5.js:12530) …

typescript angular

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

Azure Cosmos DB:Application Insights中的HTTP 400

我们正在Azure应用服务(某些Web API)中使用Application Insights,该应用程序查询.NET Core 2.1中的Azure Cosmos DB 。使用DocumentClientNuget包Microsoft.Azure.DocumentDB.Core 1.10.0中的对象完成查询,在此客户端上,我们调用CreateDocumentQuery <T>(Uri,FeedOptions)扩展方法。

现在从用户的角度来看,查询似乎可以正常工作。但是,在查看Application Insights时,我们会看到大量有关Cosmos DB的依赖项失败。我将尝试形象化在Azure门户中看到的内容:

--------------------------------------------------------------------------------------------------
| Event                                                                        | Res. | Duration |
--------------------------------------------------------------------------------------------------
| ? web-api-resource-name POST api-endpoint-name                               | 200  | 149.1 ms |
--------------------------------------------------------------------------------------------------
|   AZURE DOCUMENTDB cosmosdb-name.documents.azure.com | Create/query document | 400  |     4 ms |
--------------------------------------------------------------------------------------------------
|   AZURE DOCUMENTDB cosmosdb-name.documents.azure.com | Query documents       | 200  |     7 ms |
--------------------------------------------------------------------------------------------------
|   AZURE DOCUMENTDB cosmosdb-name.documents.azure.com | Create/query document | 400  | …
Run Code Online (Sandbox Code Playgroud)

azure azure-application-insights asp.net-core azure-cosmosdb

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

Entity Framework Core:具有持久值的计算列

我有点惊讶我没有找到有关以下问题的任何信息,所以如果我在文档中的某个地方错过了它,请原谅。使用 SQL Server(2016 本地和 Azure)和 EFCore Code First,我们尝试创建一个具有持久值的计算表列。创建列工作正常,但我不知道如何保留该值。这就是我们所做的:

modelBuilder.Entity<SomeClass>(entity =>
{
    entity.Property(p => p.Checksum)
        .HasComputedColumnSql("(checksum([FirstColumnName], [SecondColumnName]))");
});
Run Code Online (Sandbox Code Playgroud)

以下是我们实际上希望在 T-SQL 中获得的内容:

CREATE TABLE [dbo].[SomeClass]
(
    [FirstColumnName]   [NVARCHAR](10)
  , [SecondColumnName]  [NVARCHAR](10)
  , [Checksum] AS (CHECKSUM([FirstColumnName], [SecondColumnName])) PERSISTED
);
Run Code Online (Sandbox Code Playgroud)

有人能指出我正确的方向吗?

提前致谢,托比

更新:基于@jeroen-mostert 的一个好主意,我还尝试将字符串PERSISTED作为公式的一部分传递:

modelBuilder.Entity<SomeClass>(entity =>
{
    entity.Property(p => p.Checksum)
        .HasComputedColumnSql("(checksum([FirstColumnName], [SecondColumnName]) PERSISTED)");
});
Run Code Online (Sandbox Code Playgroud)

还有括号外:

modelBuilder.Entity<SomeClass>(entity =>
{
    entity.Property(p => p.Checksum)
        .HasComputedColumnSql("(checksum([FirstColumnName], [SecondColumnName])) PERSISTED");
});
Run Code Online (Sandbox Code Playgroud)

然而,令人惊讶的是,计算列仍然是用 生成的Is Persisted = No,因此该PERSISTED字符串似乎被忽略了。

sql-server entity-framework-core

8
推荐指数
2
解决办法
8384
查看次数

为什么表值函数的性能优于select direct语句?

一只忙碌的猫

我使用AdventureWorks2012进行测试.和我的问题:为什么SELECT语句直接性能低于表值函数.我只将SELECT statemnt放入表值函数和完全相反的性能.

CREATE FUNCTION [dbo].[atest1]
(
    @iBusinessEntityID  INT
)
RETURNS @t TABLE
(
    [BusinessEntityID]  INT
  , [NationalIDNumber]  NVARCHAR(15)
  , [JobTitle]          NVARCHAR(50)
)
AS
    BEGIN
        INSERT INTO @t
               SELECT 
                   [e].[BusinessEntityID]
                 , [e].[NationalIDNumber]
                 , [e].[JobTitle]
               FROM [HumanResources].[Employee] [e]
               INNER JOIN [Person].[Person] [p]
                    ON [p].[BusinessEntityID] = [e].[BusinessEntityID]
               WHERE [e].[BusinessEntityID] = @iBusinessEntityID;
        RETURN;
    END;

--TEST PERFORMANCE
SELECT 
    *
FROM [dbo].[atest1](5);
GO
SELECT 
    [e].[BusinessEntityID]
  , [e].[NationalIDNumber]
  , [e].[JobTitle]
FROM [HumanResources].[Employee] [e]
INNER JOIN [Person].[Person] [p]
     ON [p].[BusinessEntityID] = [e].[BusinessEntityID]
WHERE [e].[BusinessEntityID] = 5;
Run Code Online (Sandbox Code Playgroud)

sql-server user-defined-functions inline-functions table-functions

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

SQL-不使用GROUP BY的情况下使用CASE

如何在不GROUP BY使用CASE表达式的情况下获得值的总和SQL (或请提出实现此目标的其他最佳方法)

查询

SELECT 
    CASE
        WHEN [lab_date] <= '2018-03-24'
             AND [lab_date] >= '2018-01-01'
        THEN(ISNULL(SUM(ISNULL([cost], 0) * 5 / 100), 0))
        WHEN [lab_date] >= '2018-03-25'
        THEN(ISNULL((SUM(ISNULL([cost], 0))) - (SUM(ISNULL([cost], 0) * 5 / 100)), 0))
    END AS [tax]
FROM [LABOR];

+-------------+--------+
|  lab_date   |  cost  |
+-------------+--------+
| 2018-03-12  |  75.00 |
| 2018-03-01  | 150.00 |
| 2018-03-11  | 450.00 |
| 2018-03-13  |  37.50 |
| 2018-03-15  | 150.00 |
+-------------+--------+
Run Code Online (Sandbox Code Playgroud)

在lab_date之前与GROUP取得联系 …

sql sql-server sql-server-2008

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