小编Tom*_*Tom的帖子

返回字符串列表

我需要修改下面提到的方法来返回字符串列表.它将以contactid作为输入,并应返回问卷清单

public string GetFatcaQuestionnaire(int contactId, string questionnaireType)
{
    using (var context = new dbDealingContainer())
    {
        if (context.Connection.State == ConnectionState.Closed)
            context.Connection.Open();

        var fatcaQuestionaires = context.FatcaQuestionaires.FirstOrDefault(p => p.ContactID == contactId && p.QuestionnaireType == questionnaireType);
        return fatcaQuestionaires != null ? fatcaQuestionaires.Questionaire : null;
    }
}
Run Code Online (Sandbox Code Playgroud)

新提出的方法

public List<string> GetFatcaQuestionnaire(int contactId)
{
    using (var context = new dbDealingContainer())
    {
        if (context.Connection.State == ConnectionState.Closed)
            context.Connection.Open();

        var fatcaQuestionaires = context.FatcaQuestionaires.Select(p => p.ContactID == contactId).ToList();
        return fatcaQuestionaires.ToList();
        //return fatcaQuestionaires.ToList() != null ? fatcaQuestionaires : null;
    }
} …
Run Code Online (Sandbox Code Playgroud)

c# linq

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

Webapi方法获取字符串参数未被调用

我用两个get方法创建asp.net webapi.一个返回所有记录,而另一个应根据名为countrycode的字符串参数进行过滤.我不确定为什么使用字符串参数的get方法不会被调用.

我试过以下的uri

http://localhost:64389/api/team/'GB'
http://localhost:64389/api/team/GB
Run Code Online (Sandbox Code Playgroud)

以下是我的代码

Web API

public HttpResponseMessage Get()
        {
            var teams = _teamServices.GetTeam();
            if (teams != null)
            {
                var teamEntities = teams as List<TeamDto> ?? teams.ToList();
                if (teamEntities.Any())
                    return Request.CreateResponse(HttpStatusCode.OK, teamEntities);
            }
            return Request.CreateErrorResponse(HttpStatusCode.NotFound, "Team not found");

        }

        public HttpResponseMessage Get(string countryCode)
        {
            if (countryCode != null)
            {

                var team = _teamServices.GetTeamById(countryCode);
                if (team != null)
                    return Request.CreateResponse(HttpStatusCode.OK, team);
            }

            throw new Exception();
        }
Run Code Online (Sandbox Code Playgroud)

WebAPIConfig

public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            // …
Run Code Online (Sandbox Code Playgroud)

asp.net-web-api asp.net-web-api2

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

在 MVC5 应用程序中使用会话的最佳方法

我正在尝试在 asp.net mvc 5 应用程序中实现会话。该应用程序没有登录屏幕。应用程序检查访问该应用程序的用户是否存在于数据库中。Active Director 用户名在会话中被捕获并发送到存储过程以验证用户是否存在。如果存在,我需要在会话中存储用户配置文件信息。我创建了一个存储库类来访问数据。我从 global.asax 中的 session start 方法调用该方法。我想验证我的实现是否正确。如果信息发生更改,如何更新会话数据。

MCRHelper

 public static string GetShortname()
        {
            string username = HttpContext.Current.User.Identity.Name;
            return username.Split('\\')[1];
        }
Run Code Online (Sandbox Code Playgroud)

模型

[Serializable]
    public class UserProfileSessionData
    {
        public int UserProfileID { get; set; }
        public int EmployeeID { get; set; }
        public string Forename { get; set; }
        public string Surname { get; set; }
        public string PreferredName { get; set; }
        public string DefaultLanguageCode { get; set; }
        public string DefaultCountryCode { get; set; } …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc-5

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

Automapper vs Dapper用于映射

这个问题是要验证当前的实现是否是最佳实践和性能方面的正确方法.到目前为止,在我以前的所有公司中,我一直使用Auto Mapper将关系对象映射到域模型实体,将域模型实体映射到Dtos.ORM工具是Entity框架.在我目前的公司中,他们使用Dapper作为ORM工具,并且不使用AutoMapper,因为他们说Dapper在内部为您做映射.因此,他们构建项目的方式是创建一个单独的类库项目,该项目包含Dtos并引用Dataccess和Business层中的Dtos.Dapper返回的查询内部映射到Dtos.这些Dtos将返回到Business层,依此类推.

例如

在下面的代码中,Participant功能是Dto.

DataAccess层中的存储库文件

 public List<ParticipantFunction> GetParticipantFunctions(int workflowId)
        {
            // Update the Action for Participant
            string selectSql = @"SELECT [WFPatFunc_ID] AS WFPatFuncID
                        ,[WFFunction]
                        ,[SubIndustryID]
                        ,[DepartmentID]
                    FROM [dbo].[WF_ParticipantsFunctions]
                    WHERE [DepartmentID] = (SELECT TOP 1 [DepartmentID] FROM [dbo].[WF] WHERE [WF_ID] = @workflowId)";

            return _unitOfWork.GetConnection().Query<ParticipantFunction>(selectSql, new
            {
                workflowId = workflowId
            }).ToList();
        }
Run Code Online (Sandbox Code Playgroud)

开发人员告诉我的原因是AutoMapper只是一个开销并降低了速度,而且由于Dapper在内部进行映射,因此不需要它.

我想知道他们所遵循的做法是否合适并且没有问题.

c# model-view-controller automapper dapper

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

实体框架6中的流畅Api不兼容实体框架核心

我使用Entity Framework 6实现了Fluent API.使用EnityFrameworkCore实现相同时遇到问题.

下面是使用EntityFramework 6的Fluent API的代码

 public class CustomerConfiguration : EntityTypeConfiguration<Customers>
    {
        public CustomerConfiguration()
        {
            ToTable("Customers");
            Property(c => c.FirstName).IsRequired().HasMaxLength(50);
            Property(c => c.LastName).IsRequired().HasMaxLength(50);
            Property(c => c.Gender).IsRequired().HasMaxLength(10);
            Property(c => c.Email).IsRequired().HasMaxLength(25);
            Property(c => c.Address).IsRequired().HasMaxLength(50);
            Property(c => c.City).IsRequired().HasMaxLength(25);
            Property(c => c.State).IsOptional().HasMaxLength(15);

        }
    }


  protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Configurations.Add(new CustomerConfiguration());
            modelBuilder.Configurations.Add(new OrderConfiguration());
            modelBuilder.Configurations.Add(new ProductConfiguration());

            modelBuilder.Entity<Orders>()
           .HasRequired(c => c.Customers)
           .WithMany(o => o.Orders)
           .HasForeignKey(f => f.CustomerId);

            modelBuilder.Entity<Orders>()
                .HasMany<Products>(s => s.Products)
                .WithMany(c => c.Orders)
                .Map(cs =>
                {
                    cs.MapLeftKey("OrderRefId");
                    cs.MapRightKey("ProductRefId");
                    cs.ToTable("OrderDetails");
                });


        }
Run Code Online (Sandbox Code Playgroud)

我在EntityFrameworkCore中遇到的问题是

  1. 它可以识别CustomerConfiguration()中的ToTable和Property关键字
  2. 它在OnModelCreating方法中识别出Configurations,HasRequired,MapLeftKey,MapRightKey,ToTable关键字 …

c# entity-framework entity-framework-core ef-fluent-api asp.net-core

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

将指令扩展为不显示两位小数

我已经写了一个接受数字的指令,并且根据例如它是10,000还是10,000,000,它将返回10k,10M等.我网站中的一个屏幕需要以小数点后两位显示,而另一个屏幕不显示.我当前的实现显示最多2位小数.如何将其扩展为在需要时不显示

import { Component, OnInit, Pipe, PipeTransform } from '@angular/core';

@Pipe({
  name: 'shortNumberFormat'
})
export class ShortNumberFormatDirective implements PipeTransform {

  constructor() { }

   transform(number: any) {

    if (number == null || isNaN(number)) {
      return;
    }

    const hasMinus = String(number).charAt(0) === '-' ? true : false;
    number =  String(number).charAt(0) === '-' ?
            + String(number).substring(1, number.length)  : number;

        if (number <= 999) { // hundreds
          number = number.toFixed(2) ;
        } else if (number >= 1000 && number <= 999999) {  // thousands …
Run Code Online (Sandbox Code Playgroud)

javascript angular

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

需要高图表中的图例为方形

我已经使用 Angular 4 实现了样条图组件。我需要将图例图标显示为方形,但它显示为圆形。我觉得它是圆形的原因之一是因为,我已将标记定义为圆形。它显示绘制线的圆圈以及图例图标。我需要将其显示为绘制线条的圆形,但显示图例的方形

我已经尝试过以下方法,但它似乎并不适用。有人可以告诉我为什么它不适用吗?

legend: {
          symbolRadius: 0,
          symbolHeight: 20,
          symbolWidth: 20
        }
Run Code Online (Sandbox Code Playgroud)

目前看起来是这样的

在此输入图像描述

需要它看起来像这样

在此输入图像描述

完整代码如下

export class SplineChartComponent implements OnChanges {
    public options: any;
    chart: any;

    @Input() public series: any;
    @Input() public yaxisdata: any;

    @Input() public selectedRating: string = '';

    constructor() {
        this.options = {
            credits: {
                enabled: false
            },
            chart: {
                type: 'spline',
            },
             title:{
                 text:''
                },
                subtitle:{
                    text:''
                },
            legend: {
                align: 'right',
                verticalAlign: 'bottom',
                layout: 'horizontal',
                margin: 25,
                itemMarginTop: 0,
                symbolRadius: 0,
                symbolHeight: 20,
                symbolWidth: …
Run Code Online (Sandbox Code Playgroud)

highcharts angular

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

尽管在app.module中声明,但获取require不是角度函数错误

我试图渲染一个钟形曲线图并获得错误要求不是角度函数.我在app.module中声明了require.

如果你注意到我试图通过hellocomponent加载图表.

我为它创建了一个stackblitz.有人可以告诉我问题是什么 https://stackblitz.com/edit/angular-xgx6up

angular

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

将类型 Task&lt;IEnumerable&gt; 转换为类型 IEnumerable

我有以下类型的表达式Task<IEnumerable<PendingApprovalUserChangeRequest>>,我需要将其转换为IEnumerable<PendingApprovalUserChangeRequest>. 我怎么做 ?

Task<IEnumerable<PendingApprovalUserChangeRequest>> pendingChangeRequest = service.GetPendingChangeRequest();
Run Code Online (Sandbox Code Playgroud)

c# task async-await

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

如果 x 是 Angular 组件,则验证它是该模块的一部分

我创建了一个 Angular 应用程序。我已将导航组件的选择器放在 app.component.html 中,它是 app.module 的一部分,并收到以下错误。

ERROR in src/app/app.component.html:1:1 - error NG8001: 'app-nav' is not a known element:
1. If 'app-nav' is an Angular component, then verify that it is part of this module.
Run Code Online (Sandbox Code Playgroud)

app-nav是属于sharedmodule的nav组件的选择器。共享模块被导入到app.module中。

那么为什么应用程序导航不被识别呢?

导航组件

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

@Component({
  selector: 'app-nav',
  templateUrl: './nav.component.html',
  styleUrls: ['./nav.component.scss']
})
export class NavComponent implements OnInit {

  constructor() { }

  ngOnInit(): void {
  }

}
Run Code Online (Sandbox Code Playgroud)

共享模块

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common'; …
Run Code Online (Sandbox Code Playgroud)

angular

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

LINQ to Entities不支持LINQ表达式节点类型'ArrayLength'

我已经实现了一个linq表达式来返回结果集并得到以下错误

{"LINQ to Entities不支持LINQ表达式节点类型'ArrayLength'."}

public IEnumerable<TBI.JV.Business.Objects.Asset> GetAssetsBasicBySedols(string[] sedols)
    {
        var priceDate = DateTime.UtcNow.Date.AddMonths(-8);
        var typeList = new string[]
            {
                "UNIT TRUST",
                "OEIC",
                "INVESTMENT TRUST",
                "INVESTMENT COMPANY",
                "PENSION FUND",
                "INSURANCE BOND",
                "LISTED EQUITY",
                "PREFERENCE SHARE",
                "ZERO DIVIDEND PREF",
                "GILT (CONVENTIONAL)",
                "GILT (INDEX LINKED)",
                "AIM",
                "VCT",
                "OFFSHORE FUND",
                "ETP"
            };
        using (var dealingContext = new dbDealingContainer())
        {
            return (from fundprice in dealingContext.FundPrices
                    where (fundprice.FUND_STATUS == "ACTIVE" || fundprice.FUND_STATUS == "SUSPENDED") &&
                          (fundprice.INVNAME != null || fundprice.INVNAME != "") &&
                          !fundprice.INVNAME.StartsWith("IFSL Bestinvest") && …
Run Code Online (Sandbox Code Playgroud)

c# linq

0
推荐指数
2
解决办法
2508
查看次数

System.ArgumentNullException:'值不能为null。参数名称:键

我目前在分组逻辑中遇到错误。我正在尝试对相同产品名称的EMV中的值求和。仅通过一些列表时出现错误。我如何避免这种异常。我不知道在linq expssion中执行空检查

System.ArgumentNullException: 'Value cannot be null. Parameter name: key'
Run Code Online (Sandbox Code Playgroud)

public Dictionary<string, decimal> SumProductEmv(IEnumerable<FirmWideAllocationsViewModel> allProducts)
{
    if (allProducts == null)
        return null;

    return allProducts
        .GroupBy(product => product.ProductName)
        .Select(group => new
        {
            ProductName = group.Key, // this is the value you grouped on - the ProductName
            EmvSum = group.Sum(item => item.Emv)
        })
        .ToDictionary(x => x.ProductName, x => x.EmvSum);
}
Run Code Online (Sandbox Code Playgroud)

c# linq

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

c#无法在字符串中插入换行符

我在下面的短信中插入换行符时遇到问题。目前我正在使用 Environment.NewLine 但这似乎不起作用。这是它的显示方式。

在此处输入图片说明

代码

  error =
                            @"You cannot split a sale@
                              <ul>
                                <li>With yourself.</li>            
                                <li>A representative that has not completed their IBA and not been approved by compliance.</li>
                                <li>A terminated representative.</li>
                                </ul>".Replace("@", Environment.NewLine)
Run Code Online (Sandbox Code Playgroud)

我基本上想像这样展示它

You cannot split a sale

•   With yourself.            
•   A representative that has not completed their IBA and not been approved by compliance.
•   A terminated representative.
Run Code Online (Sandbox Code Playgroud)

编辑

html

<div class="row">
      <div class="col-12 col-lg-6">
        <div *ngIf="infoMessage" class="notification warning">
          <fa-icon [icon]="['fas', 'info-circle']"></fa-icon>
          <span [innerHTML]="infoMessage"></span>
        </div>    
      </div>
    </div> …
Run Code Online (Sandbox Code Playgroud)

html c#

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