小编Nat*_*kle的帖子

无法确定外键的复合外键排序

Person是包含所有用户的用户模型.更改模型包括EngineerId和ManagerId,两者都是Person ID.为什么我收到此错误?

无法在类型ProjectName.Models.Change上确定外键的复合外键排序.在复合外键属性上使用ForeignKey数据批注时,请确保使用Column数据批注或Fluent API指定顺序.

public class Change
{
    [Key]
    public int ChangeId { get; set; }

    [Required(ErrorMessage = "Change description is required.")]
    [Display(Name = "Change Description")]
    [DataType(DataType.MultilineText)]
    public string ChangeDescription { get; set; }

    [Required(ErrorMessage = "Change date is required.")]
    [Display(Name = "Date of Change")]
    [DataType(DataType.Date)]
    public DateTime ChangeDate { get; set; }

    [Required(ErrorMessage = "Time is required.")]
    [Display(Name = "Time of Change")]
    [DataType(DataType.Time)]
    public DateTime ChangeTime { get; set; }

    [Required(ErrorMessage = "Engineer name is required.")]
    [Display(Name = "Engineer")] …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework

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

模型状态无效,但为什么?

在“创建”页面上提交 POST 时,我返回查看,并且调试已将其范围缩小到模型状态无效,但我不确定为什么它无效。

这就是我想要做的。我添加了一个要上传的文件,该文件在 create 方法中运行良好,直到我需要从下拉菜单中添加更多详细信息。最初,当我只需要文件时,它看起来像这样:

public ActionResult Create(HttpPostedFileBase file)
        {
            ViewBag.EnvironmentTypeId = new SelectList(db.environmenttypes, "EnvironmentTypeId", "EnvironmentTypeName", 1);
            if (ModelState.IsValid)
            {
                IO io = new IO();
                if (file != null)
                {
                    AppUpdate updateLog = io.UpdateApp(file, env.EnvironmentTypeId);
                    updateLog.UserName = User.Identity.Name;
                    updateLog.EnvironmentTypeId = env.EnvironmentTypeId;
                    db.appupdates.Add(updateLog);
                    db.SaveChanges();
                }
                else
                {
                    return RedirectToAction("Create");
                }
                return RedirectToAction("Index");
            }

            return View();
        }
Run Code Online (Sandbox Code Playgroud)

所以我在模型中添加了更多内容以获取详细信息:

public ActionResult Create([Bind(Include="EnvironmentTypeId")] AppUpdate env, HttpPostedFileBase file)
        {
            ViewBag.EnvironmentTypeId = new SelectList(db.environmenttypes, "EnvironmentTypeId", "EnvironmentTypeName", 1);
            if (ModelState.IsValid)
            {
                IO io = new IO(); …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-core-mvc

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

在Try/Catch Block中使用Response.Redirect(url)

如果我对try/catch块中的错误的响应是将用户重定向到错误页面,则try/catch块的行为就像没有时出现错误一样.如果我改变它做其他事情,代码工作正常.

例:

try
{
    //do this SQL server stuff
}
catch
{
   Response.Redirect(error.htm)
   //Change this to lblErr.Text = "SQL ERROR"; and the code in try works fine.
}
Run Code Online (Sandbox Code Playgroud)

从另一篇文章我了解到,Response.Redirect()方法有一个布尔重载.我尝试了true和false,并且try/catch块仍然表现得好像有错误.

这是怎么回事?

.net c# response.redirect try-catch

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

如何在node.js中的http PUT主体中使用JSON?

请参阅下面的代码.我正在尝试在我的请求正文中发送{"status":"accepted"}.我一直从API返回的错误是:

{"message":"Unable to parse JSON in request body.","code":"invalid_json"}

我可以在Swift中使这个工作,但是我正在使用带有设置的字典对象并将其序列化.我不知道如何在Node.JS中这样做.

var https = require('https')

var options = {
    "host": "sandbox-api.uber.com",
    "path": "/v1/sandbox/requests/" + req.body.request_id,
    "method": "PUT",
    "headers": { 
    "Authorization" : "Bearer " + req.body.bearer_token,
    "Content-Type" : "application/json",
    },
    "body" : {
        "status" : "accepted"
    }
}

callback = function(response) {
    var str = ''
    response.on('data', function(chunk){
        str += chunk
    })

    response.on('end', function(){
        console.log(str)
    })
}

https.request(options, callback).end()
Run Code Online (Sandbox Code Playgroud)

javascript node.js http-request uber-api

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

如何在Swift中引用类?

就iOS语言而言,我真的只了解Swift,但是我试图学习如何从Objective C进行翻译。我做得很好(我知道C#的帮助),并以此为翻译指南,但是我在指南中没有提到的某些点上感到困惑。

例如,从本教程开始,尝试翻译这些说明对我来说绝对没有意义:

打开新添加的标头CERangeSliderKnobLayer.h并将其内容替换为以下内容:

#import <QuartzCore/QuartzCore.h>

@class CERangeSlider;

@interface CERangeSliderKnobLayer : CALayer

@property BOOL highlighted;
@property (weak) CERangeSlider* slider;

@end
Run Code Online (Sandbox Code Playgroud)

在Swift中会是什么样?

我知道该怎么做import QuartzCore,其余的...

什么是@Class斯威夫特?

什么是 @interface?

我有点明白了@property,我猜我只是这样做:

var highlighted: bool
weak var slider: CERangeSlider
Run Code Online (Sandbox Code Playgroud)

我的意思是,当前我新创建的类如下所示:

import UIKit
import QuartzCore

class CERangeSliderKnobLayer: CALayer {

}
Run Code Online (Sandbox Code Playgroud)

那会去哪里?我假设在课堂上。特别是属性设置。

objective-c code-translation swift

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

Swift:从日期选择器获取正确的时区?

我试图使用时间格式化程序从日期选择器中快速获取正确的时区,但它不起作用。我得到的是 UTC,而不是 EST。

1)如果我打印 dateFormatter.stringFromDate(datePicker) 我得到 EST,但是

2)我不需要字符串,我需要 EST 中的 NSDate 所以

3)我可以用它来获取EST中的timeIntervalSinceDate(NSDate)。

我试图将其从字符串返回到 NSDate 的技巧如下所示,但没有奏效。它仍然是 UTC,并且自日期以来的时间间隔不正确。

dateFormatter.locale = NSLocale.currentLocale()
dateFormatter.timeZone = NSTimeZone.localTimeZone()
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
let date: NSDate = dateFormatter.dateFromString(dateFormatter.stringFromDate(datePicker))!
print(date)
print(date.timeIntervalSinceDate(datePicker))
Run Code Online (Sandbox Code Playgroud)

datepicker nsdate nsdateformatter swift

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

使用元素和拆分获取 Terraform 中的第一个项目而不是最后一个项目

我们尝试将动态名称应用于防火墙规则,以便使用基于实例组 URL 列表的 terraform 在 GCP 中打开 8089 和 8843。它没有获取该结果并向我们提供 url 中的最后一项,而是为我们提供 https:

tf:

#This is to resolve an error when deploying to nginx
  resource "google_compute_firewall" "ingress" {
  for_each      = toset(google_container_cluster.standard-cluster.instance_group_urls)
  description   = "Allow traffic on ports 8843, 8089 for  nginx ingress"
  direction     = "INGRESS"
  name          = element(split("/", each.key), length(each.key))
  network       = "https://www.googleapis.com/compute/v1/projects/${local.ws_vars["project-id"]}/global/networks/${local.ws_vars["environment"]}"
  priority      = 1000
  source_ranges = google_container_cluster.standard-cluster.private_cluster_config.*.master_ipv4_cidr_block
  target_tags = [
    element(split("/", each.key), length(each.key))
  ]

  allow {
    ports = [
      "8089",
    ]
    protocol = "tcp"
  }
  allow {
    ports …
Run Code Online (Sandbox Code Playgroud)

split element nginx terraform

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

为什么我会收到此 GRPCProvider UpgradeResourceState terraform 错误?

问题:为了解决表的 GCP 数据目录标记的一些其他问题,将 terraform 从 0.14.4 更新到 1.0.8 后,我在尝试应用 terraform 时遇到了新错误。

\n
\xe2\x94\x82 Error: Request cancelled\n\xe2\x94\x82 \n\xe2\x94\x82   with module.ds-bigquery.google_bigquery_table.prism_tables_no_partition["co.expenses"],\n\xe2\x94\x82   on ds-bigquery/bq-prism-tables.tf line 249, in resource "google_bigquery_table" "prism_tables_no_partition":\n\xe2\x94\x82  249: resource "google_bigquery_table" "prism_tables_no_partition" {\n\xe2\x94\x82 \n\xe2\x94\x82 The plugin.(*GRPCProvider).UpgradeResourceState request was cancelled.\n
Run Code Online (Sandbox Code Playgroud)\n

和这个痕迹

\n
Stack trace from the terraform-provider-google_v3.61.0_x5 plugin:\n\npanic: interface conversion: interface {} is string, not map[string]interface {}\n\ngoroutine 4466 [running]:\ngithub.com/hashicorp/terraform-provider-google/google.bigQueryTablecheckNameExists(0xc000df9600, 0x1, 0x1, 0x0, 0x2d21b78)\n    /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/hashicorp/terraform-provider-google/google/resource_bigquery_table.go:26 +0x164\ngithub.com/hashicorp/terraform-provider-google/google.jsonCompareWithMapKeyOverride(0x2526520, 0xc000543940, 0x2526520, 0xc000543ae0, 0x2d22688, 0x40c201, 0xc000df9f30, 0x10)\n    /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/hashicorp/terraform-provider-google/google/resource_bigquery_table.go:47 +0x63f\ngithub.com/hashicorp/terraform-provider-google/google.jsonCompareWithMapKeyOverride(0x275dac0, 0xc000c5ec00, 0x275dac0, 0xc000c5f140, 0x2d22688, 0x1, 0xc000f90120, 0xc000fd1000)\n …
Run Code Online (Sandbox Code Playgroud)

terraform terraform-provider-gcp

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

如何摆脱这种特殊的循环?

我有一个while循环,当我按下按钮时开始.我正在使用它来维护与另一台计算机上的服务的通信.问题是,当我从另一台计算机上收到"已完成"消息时,我需要它打破while循环并停止监听,直到再次按下该按钮.我所做的一切似乎都没有把它打破.

请注意整个过程在自己的线程中执行.

我试着休息一下; 就在交换机中第一个案例结束之前,没有这样的运气,我不确定是不是因为它是一个期望中断的switch语句; 案件之间或原因是什么.我也尝试过回归; 在那里,但它仍然不会爆发.我最终必须关闭应用程序并重新启动它以再次使用该按钮.

TcpClient client = new TcpClient(serverIP, 11000);
NetworkStream stream = client.GetStream();
Byte[] bytes = new Byte[256];
String data = null;
int i;

stream.Write(copy, 0, copy.Length);


while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
{
    data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
    //MessageBox.Show(data);
    switch (data)
    {
        case "Completed":
            this.Invoke((MethodInvoker)delegate
            {
                progressBar1.Value = 0;
                progressBar1.Visible = false;
                progressBar1.Update();
                if (prod)
                {
                    sqlLink.setProdFile(imageName, destFileName);
                } else
                {
                    sqlLink.setTestFile(imageName, destFileName);
                    if (sqlLink.getTestVM(imageName) != "")
                    {
                        if (message.Text("Test VM", "Power …
Run Code Online (Sandbox Code Playgroud)

c# tcplistener while-loop

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

在 C# 中运行基本 PowerShell 命令时出现错误 cmdlet 未找到

我有一个 C# 控制台程序,我想运行 PowerShell 命令而不是脚本,但无论我尝试在 PowerShell 运行空间中运行什么命令,都会收到一条错误消息,指出找不到 cmdlet。它可以像下面这样简单:

static void Main(string[] args)
{
    try
    {
        using (Runspace runspace = RunspaceFactory.CreateRunspace())
        {
            runspace.Open();
            PowerShell ps = PowerShell.Create();
            ps.Runspace = runspace;
            ps.AddCommand("(Get-Date).AddDays(1)");
            var result = ps.Invoke();

            Console.WriteLine(result);
        }
    }
    catch (Exception ex)
    {
        Console.WriteLine("Error: " + ex.ToString());
    }
}
Run Code Online (Sandbox Code Playgroud)

我可以在 PowerShell 命令行中键入此命令,它运行得非常好。我不必添加任何模块来运行它。我缺少什么?

c# powershell

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