[Range(1900, DateTime.Now.Year, ErrorMessage = "Please enter a valid year")]
Run Code Online (Sandbox Code Playgroud)
这行不通。对于“ DateTime.Now.Year”,它告诉我
An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type
Run Code Online (Sandbox Code Playgroud) String.Join("<br>", ProductList)
Run Code Online (Sandbox Code Playgroud)
ProductList是一个List.所以,这会返回一个整洁的小:
Item1
Item2
Item3等
我需要做的就是删除第一项.
String.Join("<br>", ProductList.RemoveAt(0))
Run Code Online (Sandbox Code Playgroud)
这不起作用,因为RemoveAt返回void.我确信这很简单......当我看到答案时,我可能会在额头上咂嘴.
我一直在这里查看其他线程,以了解如何在linq中执行GroupBy。我正在使用对其他人有用的EXACT语法,但是,它不起作用。
这是查询:
var results = from p in pending
group p by p.ContactID into g
let amount = g.Sum(s => s.Amount)
select new PaymentItemModel
{
ContactID = g.ContactID, // <--- Error here
Amount = amount
};
Run Code Online (Sandbox Code Playgroud)
pending
是一个List<T>
包含其他列ContactID
和的列,Amount
但这是我对此查询仅关心的两列。
问题是,在的内部select new
,g.
不会给我原始列表内的任何列pending
。当我尝试时,我得到:
IGrouping
<int, LeadPurchases>
不包含ContactID的定义,也没有扩展方法等等……
这是我要模拟的SQL:
SELECT
lp.PurchasedFromContactID,
SUM (lp.Amount)
FROM
LeadPurchases lp
GROUP BY
lp.PurchasedFromContactID
Run Code Online (Sandbox Code Playgroud) 我们有一个需要每秒更新的显示板.对服务器的AJAX调用触发存储过程,这是一个非常简单的SELECT语句,执行只需几毫秒.
最初,由于网络延迟(或太阳黑子,或谁知道什么),这个AJAX过程会(偶尔,很少)超时.通过调整我们如何处理计时器并将其设置timeout
为0,我们已经拥有它,所以它现在运行稳定,超时永远不会发生......
话虽如此,我仍然担心暂停仍可能发生.如果发生,目标是它会继续前进.基本上,忽略超时,再试一次......永远.没有MaxError,RetryLimit或TryCount等.
这就是我现在拥有的:
setTimeout(function run() {
// When the timer elapses, get the data from the server
GetData();
setTimeout(run, _refreshRate);
}, 1000);
function GetData() {
//console.log("Attempting to obtain the data...");
jQuery.ajax({
url: "something.ashx",
type: "GET",
contentType: 'application/json; charset=utf-8',
success: function(resultData) {
//console.log("Got the data.");
ParseJson(resultData);
// show the last refresh date and time
$('#refreshTime').html(GetDateTime());
},
error : function(xhr, textStatus, errorThrown) {
if (textStatus == 'timeout') {
//console.log("Timeout occured while getting data from the server. Trying …
Run Code Online (Sandbox Code Playgroud) 缩小后看我的查询看起来像这样:
SELECT
...
FROM
Settings s
LEFT JOIN OrganizationUserSettings ous ON s.SettingID = ous.SettingID
AND (ProfileID = @ProfileID OR ProfileID IS NULL)
Run Code Online (Sandbox Code Playgroud)
现在,在OrganizationUserSettings
表格中我有两行看起来像这样:
ID SettingID ProfileID
----------------------------
1 3 NULL
2 3 50
Run Code Online (Sandbox Code Playgroud)
正如所料,在我的结果中,我得到两行.但我需要只获得一排.如果有匹配ProfileID = @ProfileID
,那么我需要那个.如果没有,那么我将采用那个为NULL的那个.
或者,更好......总之,这是我真正的问题.我可以像这样做一个巨大的IF ELSE:
IF (@ProfileSys IS NULL)
BEGIN
SELECT
...
FROM
Settings s
LEFT JOIN OrganizationUserSettings ous ON s.SettingID = ous.SettingID
AND (ProfileID IS NULL)
END
ELSE
BEGIN
SELECT
...
FROM
Settings s
LEFT JOIN OrganizationUserSettings ous ON s.SettingID = ous.SettingID …
Run Code Online (Sandbox Code Playgroud) 我在这里遗漏了一些明显的东西.一张图片价值10k字.这些是Chrome中DOM调试的一些截图.
HTML:
查看脚本,在调试中暂停:
为什么ammount
不填充?(忽略错误拼写ammount
...我会解决它!!)
我正在调用第三方API,返回的json字符串如下所示:
{
"data":[
{"id":197567,"name":"101","url":"http://www.foobar1.com"},
{"id":197568,"name":"102","url":"http://www.foobar2.com"},
.....
{"id":197569,"name":"120","url":"http://www.foobar20.com"}
],
"offset":0,
"pageSize":2,
"count":20
}
Run Code Online (Sandbox Code Playgroud)
然后我有一个课FoorBarURIs
:
private class FoorBarURLs
{
public int id { get; set; }
public string name { get; set; }
public string url { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
因此,我不在乎the offset
或the pagesize
或the count
。我需要的只是里面的数据data
。
鉴于我刚开始只是一个字符串,如何从中提取该列表,data
以便执行此操作:
List<FoorBarURLs> myList = JsonConvert.DeserializeObject<List<FoorBarURLs>>(???)
Run Code Online (Sandbox Code Playgroud) 我有一个TableA
包含几列的列,其中一列是一个Computed
值,另一列是a DateTime
的默认值GETDATE()
。
然后,我有另一个表,TableA_Staging
我想将其用作批量插入的原始转储表。该表看起来很像TableA
,但有一些预期的差异,其中之一就是其中没有Computed
或DateTime
列。
批量插入后TableA_Staging
,现在需要将数据从TableA_Staging
移到TableA
。我在这两列中遇到了麻烦。让我们假设 TableA
看起来像这样:
TableA
-----------
TableAId (INT non-unique, non-auto-incrementing PK)
Column1 (String PK)
Column2
ColumnComputed
ColuomnDateTime
Run Code Online (Sandbox Code Playgroud)
和...
TableA_Staging
-----------
TableAID (this value populated in C# code)
Column1
Column2
Run Code Online (Sandbox Code Playgroud)
现在,我正在尝试这样做:
INSERT INTO TableA
SELECT TableAID, Column1, Column2 FROM TableA_Staging WHERE TableAID > X
Run Code Online (Sandbox Code Playgroud)
但是我得到这个错误:
列名或提供的值数与表定义不匹配。
我认为这是在抱怨,因为我没有为ColumnComputed
或提供任何东西ColuomnDateTime
?但是,如果是这样,我认为我不需要为它们提供值,因为其中一个是经过计算的,而另一个具有默认值。
这个问题与以下问题非常相似: 使用LINQ可以在一个List <>中获得项目,而不在另一个List <>中。但是这些差异足以使我难以确定LINQ语法。
我有两个清单:
List<Fubar> fewBarNew
List<string> existingProviderIDs
Run Code Online (Sandbox Code Playgroud)
其中Fubar
的样子:
Class Fubar
{
int FunbarId int {get; set;}
....
....
string ProviderID {get; set;}
}
Run Code Online (Sandbox Code Playgroud)
现在,我要从fewBarNew
中FewBarNew.ProviderID
存在的任何实例中删除existingProviderIDs
。
fewBarNew = fewBarNew.Where(f => !existingProviderIdList.Any(ep => ?????).ToList();
Run Code Online (Sandbox Code Playgroud) I watched some tutorials on Youtube for a scribt I want to have in my Unity project. In minute 28:13 https://www.youtube.com/watch?v=b87iVclVT2E you can see the important part of the scribt and here is my copy of it:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour {
public CharacterController2D controller;
public Animator animator;
public float runSpeed = 40f;
float horizontalMove = 0f;
bool jump = false;
bool crouch = false;
void Update(){
horizontalMove = Input.GetAxisRaw ("Horizontal") * runSpeed; …
Run Code Online (Sandbox Code Playgroud) 我试图捕获某个变量的值,并在它为null或未定义时执行某些操作.
$(".change-engineer").change(function (e) {
var prevContactID = $(this).data('prev-value');
alert(prevContactID.value); // this shows "undefined"
if (prevContactID.value === null)
{
// we never get here
}
if (prevContactID.value === "undefined")
{
// we never get here
}
$.ajax({
type: 'POST',
url: '@Url.Action("ChangeProposalEngineer", "RequestForQuotes")',
data: { "prevContactID": prevContactID },
cache: false,
complete: function (data) {
...
}
});
});
Run Code Online (Sandbox Code Playgroud)
在服务器端,我可以打开一个断点,ChangeProposalEngineer
值为prevContactID
"null".
但在客户端,这个:alert(prevContactID.value);
弹出"未定义".但是,我似乎无法弄清楚当该值为null时如何进入if-then.
c# ×6
jquery ×3
asp.net ×2
javascript ×2
linq ×2
sql ×2
sql-server ×2
t-sql ×2
.net ×1
ajax ×1
html ×1
json ×1
json.net ×1
list ×1
monodevelop ×1
settimeout ×1
validation ×1