下面的 SQL 命令是如何工作的?
exec sp_executesql N'SET NOCOUNT ON;
DECLARE @inserted0 TABLE ([Id] int, [_Position] [int]);
MERGE [OrderLine] USING (
VALUES (@p1, @p2, 0),
(@p3, @p4, 1),
(@p5, @p6, 2),
(@p7, @p8, 3)) AS i ([Item], [OrderId], _Position) ON 1=0
WHEN NOT MATCHED THEN
INSERT ([Item], [OrderId])
VALUES (i.[Item], i.[OrderId])
OUTPUT INSERTED.[Id], i._Position
INTO @inserted0;
SELECT [t].[Id] FROM [OrderLine] t
INNER JOIN @inserted0 i ON ([t].[Id] = [i].[Id])
ORDER BY [i].[_Position];
',N'@p1 nvarchar(64),@p2 int,@p3 nvarchar(64),@p4 int,@p5 nvarchar(64),@p6 int,@p7 nvarchar(64),@p8 int',@p1=N'Item-1',@p2=1,@p3=N'Item-2',@p4=1,@p5=N'Item-3',@p6=1,@p7=N'Item-4',@p8=1
Run Code Online (Sandbox Code Playgroud)
(它由 …
我正在使用 ASP.NET Core WebAPI,我想为名为“Item”的对象执行 CRUD。我正在使用 EF Core 来处理 SQL 数据库,并且有两个模型来代表我的对象。
我的 HTTP GET one 和 HTTP GET much 方法的工作方式如下
获取 ItemRepository 实例
获取一个或多个ItemEntity
使用 AutoMapper将其映射到ItemDto这在我的构造函数中初始化,例如
m_itemDtoMapper = new Mapper(new MapperConfiguration(cfg => cfg.CreateMap<ItemEntity, ItemDto>()));
Run Code Online (Sandbox Code Playgroud)
在我的 WebAPI 方法中,我使用以下行将其映射到 ItemDto(对于 GET 许多情况):
var itemDtos = m_itemDtoMapper.Map<IEnumerable<ItemEntity>, ICollection<ItemDto>>(items);
Run Code Online (Sandbox Code Playgroud)
这很有效,并且 AutoMapper 非常强大。我现在的问题是:
当我通过value
关键字在 setter 中分配一个值时,它会起作用。但是为什么当我尝试通过属性的名称分配值时它不起作用,该名称应该保持相同的分配值?
在下面的例子中,我value
在 setter 中使用关键字,它工作得很好,我得到了预期的输出 -
private int i = 1;
public int prop
{
get { return i; }
set { i = value }
}
public void Print()
{
Console.WriteLine(i)
}
static void Main ()
{
Program p = new Program();
p.prop = 5;
Console.WriteLine(p.prop); // outputs 5
p.Print(); // outputs 5
}
Run Code Online (Sandbox Code Playgroud)
但是在下面的示例中,我使用属性名称prop
而不是value
关键字,并且它不会将新值分配给i
变量 -
private int i = 1;
public int prop
{
get { return …
Run Code Online (Sandbox Code Playgroud) 我有这段代码应该接受变量usersResp
,看看它是否与yes
数组中的元素(即在Yes
方法中)匹配并打印出变量Case
。根据匹配,0
如果没有匹配(数组中没有与 相同的元素usersResp
)或者1
元素匹配,则应该是。
这是代码。
static void Main(string[] args)
{
string usersResp = "y";
int Case = 0;
Yes(usersResp, Case);
Console.WriteLine(Case);
}
static void Yes(string UserResponse, int Case)
{
string[] yes = new string[] { "y", "Y", "Yes", "yes", "yup", "Yup", "ok", "Ok", "Alright", "alright", "yeah", "Yeah", "Sure", "sure", "of course", "Of course", "k", "K" };
for (int i = 0; i < yes.Length; i++)
{
if (UserResponse …
Run Code Online (Sandbox Code Playgroud) 考虑下面的Customer
课程 -
public class Customer
{
public int Id { get; set; }
public string Name { get; set; }
public List<Product> Products { get; set; }
}
public class Product
{
public string Name { get; set; }
public int Price { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
如果我有一个List<Purchase>
,在哪里Purchase
-
public class Purchase
{
public int CustomerId { get; set; }
public string CustomerName { get; set; }
public string ProductName { get; set; }
public …
Run Code Online (Sandbox Code Playgroud) 我正在尝试将 Angular HTML 页面数据发送到 MVC 核心。最后有兴趣得到回应。所以我使用 subscribe 方法,但它显示了这个错误 -
参数“res”隐式具有“any”类型。
这是我的代码
import { Component } from '@angular/core';
import { Patient } from './app.model';
import {HttpClient} from "@angular/common/http"
import { Observable, observable } from 'rxjs';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
patientObj: Patient = new Patient();
constructor(public httpClient:HttpClient){}
Add() {
//https://localhost:44331/Patient/SubmitPatient ServerSide Page for display record
alert(this.patientObj.id);
var observable=this.httpClient.post("https://localhost:44331/Patient/SubmitPatient", this.patientObj);
observable.subscribe(res=> this.Success(res), res=> this.Error(res));
}
Success(res) {
alert(res);
}
Error(res) {
alert(res);
}
}
Run Code Online (Sandbox Code Playgroud)
编辑 …
这里有一个奇怪的...我有以下 C# 代码:
static void Main(string[] args)
{
try
{
var url = "https://www.nordea.com/wemapp/api/fi/lists/currency/electronicExchangeFI.dat";
var result = DownloadData(url);
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
private static string DownloadData(string url)
{
var webClient = new WebClient();
byte[] xmlData = webClient.DownloadData(url);
webClient.Dispose();
string data = string.Empty;
if (xmlData.Length > 0)
{
data = System.Text.Encoding.Default.GetString(xmlData);
}
return data;
}
Run Code Online (Sandbox Code Playgroud)
使用这个特定的网站(一些汇率数据),上述作为 .NET Core/5 控制台应用程序失败,但它在 .NET Framework (4.7) 中按预期工作
在 .NET Core 中,我在方法上遇到以下异常webClient.DownloadData(url);
-
WebClient 请求期间发生异常。
内部异常是
响应提前结束,预计至少有 1 个额外字节。
我也试过使用, …
c# ×5
.net-core ×2
angular ×1
asp.net-core ×1
automapper ×1
linq ×1
properties ×1
sql ×1
sql-insert ×1
sql-server ×1