我正在尝试根据日期返回数组中的记录子集。
我的代码如下所示:
<!ELEMENT dblp (article|inproceedings|proceedings|book|incollection|
phdthesis|mastersthesis|www)*>
<!ENTITY % field "author|editor|title|booktitle|pages|year|address|journal|volume|number|month|url|ee|cdrom|cite|publisher|note|crossref|isbn|series|school|chapter">
<!ELEMENT article (%field;)*>
<!ATTLIST article
key CDATA #REQUIRED
mdate CDATA #IMPLIED
publtype CDATA #IMPLIED
reviewid CDATA #IMPLIED
rating CDATA #IMPLIED
>
<!ELEMENT inproceedings (%field;)*>
<!ATTLIST inproceedings key CDATA #REQUIRED
mdate CDATA #IMPLIED
publtype CDATA #IMPLIED
>
<!ELEMENT proceedings (%field;)*>
<!ATTLIST proceedings key CDATA #REQUIRED
mdate CDATA #IMPLIED
publtype CDATA #IMPLIED
>
<!ELEMENT book (%field;)*>
<!ATTLIST book key CDATA #REQUIRED
mdate CDATA #IMPLIED
publtype CDATA #IMPLIED
>
<!ELEMENT incollection (%field;)*>
<!ATTLIST incollection key CDATA #REQUIRED
mdate CDATA #IMPLIED
publtype CDATA #IMPLIED
>
<!ELEMENT phdthesis (%field;)*>
<!ATTLIST phdthesis key CDATA #REQUIRED
mdate CDATA #IMPLIED
publtype CDATA #IMPLIED
>
<!ELEMENT mastersthesis (%field;)*>
<!ATTLIST mastersthesis key CDATA #REQUIRED
mdate CDATA #IMPLIED
publtype CDATA #IMPLIED
>
<!ELEMENT www (%field;)*>
<!ATTLIST www key CDATA #REQUIRED
mdate CDATA #IMPLIED
publtype CDATA #IMPLIED
>
<!ELEMENT author (#PCDATA)>
<!ATTLIST author
aux CDATA #IMPLIED
bibtex CDATA #IMPLIED
>
<!ELEMENT editor (#PCDATA)>
<!ATTLIST editor
aux CDATA #IMPLIED
>
<!ELEMENT address (#PCDATA)>
<!ENTITY % titlecontents "#PCDATA|sub|sup|i|tt|ref">
<!ELEMENT title (%titlecontents;)*>
<!ATTLIST title
bibtex CDATA #IMPLIED
>
<!ELEMENT booktitle (#PCDATA)>
<!ELEMENT pages (#PCDATA)>
<!ELEMENT year (#PCDATA)>
<!ELEMENT journal (#PCDATA)>
<!ELEMENT volume (#PCDATA)>
<!ELEMENT number (#PCDATA)>
<!ELEMENT month (#PCDATA)>
<!ELEMENT url (#PCDATA)>
<!ELEMENT ee (#PCDATA)>
<!ELEMENT cite (#PCDATA)>
<!ELEMENT school (#PCDATA)>
<!ELEMENT publisher (#PCDATA)>
<!ATTLIST publisher
href CDATA #IMPLIED
>
<!ELEMENT note (#PCDATA)>
<!ATTLIST note
type CDATA #IMPLIED
>
<!ELEMENT cdrom (#PCDATA)>
<!ATTLIST cite
label CDATA #IMPLIED
ref CDATA #IMPLIED
>
<!ELEMENT crossref (#PCDATA)>
<!ELEMENT isbn (#PCDATA)>
<!ELEMENT chapter (#PCDATA)>
<!ELEMENT series (#PCDATA)>
<!ATTLIST series
href CDATA #IMPLIED
>
<!ELEMENT layout ANY>
<!ATTLIST layout
logo CDATA #IMPLIED
>
<!ELEMENT ref (#PCDATA)>
<!ATTLIST ref href CDATA #REQUIRED>
<!ELEMENT sup (%titlecontents;)*>
<!ELEMENT sub (%titlecontents;)*>
<!ELEMENT i (%titlecontents;)*>
<!ELEMENT tt (%titlecontents;)*>
<!ENTITY reg "®">
<!ENTITY micro "µ">
<!ENTITY times "×">
<!ENTITY Agrave "À" ><!-- capital A, grave accent -->
<!ENTITY Aacute "Á" ><!-- capital A, acute accent -->
<!ENTITY Acirc "Â" ><!-- capital A, circumflex accent -->
<!ENTITY Atilde "Ã" ><!-- capital A, tilde -->
<!ENTITY Auml "Ä" ><!-- capital A, dieresis or umlaut mark -->
<!ENTITY Aring "Å" ><!-- capital A, ring -->
<!ENTITY AElig "Æ" ><!-- capital AE diphthong (ligature) -->
<!ENTITY Ccedil "Ç" ><!-- capital C, cedilla -->
<!ENTITY Egrave "È" ><!-- capital E, grave accent -->
<!ENTITY Eacute "É" ><!-- capital E, acute accent -->
<!ENTITY Ecirc "Ê" ><!-- capital E, circumflex accent -->
<!ENTITY Euml "Ë" ><!-- capital E, dieresis or umlaut mark -->
<!ENTITY Igrave "Ì" ><!-- capital I, grave accent -->
<!ENTITY Iacute "Í" ><!-- capital I, acute accent -->
<!ENTITY Icirc "Î" ><!-- capital I, circumflex accent -->
<!ENTITY Iuml "Ï" ><!-- capital I, dieresis or umlaut mark -->
<!ENTITY ETH "Ð" ><!-- capital Eth, Icelandic -->
<!ENTITY Ntilde "Ñ" ><!-- capital N, tilde -->
<!ENTITY Ograve "Ò" ><!-- capital O, grave accent -->
<!ENTITY Oacute "Ó" ><!-- capital O, acute accent -->
<!ENTITY Ocirc "Ô" ><!-- capital O, circumflex accent -->
<!ENTITY Otilde "Õ" ><!-- capital O, tilde -->
<!ENTITY Ouml "Ö" ><!-- capital O, dieresis or umlaut mark -->
<!ENTITY Oslash "Ø" ><!-- capital O, slash -->
<!ENTITY Ugrave "Ù" ><!-- capital U, grave accent -->
<!ENTITY Uacute "Ú" ><!-- capital U, acute accent -->
<!ENTITY Ucirc "Û" ><!-- capital U, circumflex accent -->
<!ENTITY Uuml "Ü" ><!-- capital U, dieresis or umlaut mark -->
<!ENTITY Yacute "Ý" ><!-- capital Y, acute accent -->
<!ENTITY THORN "Þ" ><!-- capital THORN, Icelandic -->
<!ENTITY szlig "ß" ><!-- small sharp s, German (sz ligature) -->
<!ENTITY agrave "à" ><!-- small a, grave accent -->
<!ENTITY aacute "á" ><!-- small a, acute accent -->
<!ENTITY acirc "â" ><!-- small a, circumflex accent -->
<!ENTITY atilde "ã" ><!-- small a, tilde -->
<!ENTITY auml "ä" ><!-- small a, dieresis or umlaut mark -->
<!ENTITY aring "å" ><!-- small a, ring -->
<!ENTITY aelig "æ" ><!-- small ae diphthong (ligature) -->
<!ENTITY ccedil "ç" ><!-- small c, cedilla -->
<!ENTITY egrave "è" ><!-- small e, grave accent -->
<!ENTITY eacute "é" ><!-- small e, acute accent -->
<!ENTITY ecirc "ê" ><!-- small e, circumflex accent -->
<!ENTITY euml "ë" ><!-- small e, dieresis or umlaut mark -->
<!ENTITY igrave "ì" ><!-- small i, grave accent -->
<!ENTITY iacute "í" ><!-- small i, acute accent -->
<!ENTITY icirc "î" ><!-- small i, circumflex accent -->
<!ENTITY iuml "ï" ><!-- small i, dieresis or umlaut mark -->
<!ENTITY eth "ð" ><!-- small eth, Icelandic -->
<!ENTITY ntilde "ñ" ><!-- small n, tilde -->
<!ENTITY ograve "ò" ><!-- small o, grave accent -->
<!ENTITY oacute "ó" ><!-- small o, acute accent -->
<!ENTITY ocirc "ô" ><!-- small o, circumflex accent -->
<!ENTITY otilde "õ" ><!-- small o, tilde -->
<!ENTITY ouml "ö" ><!-- small o, dieresis or umlaut mark -->
<!ENTITY oslash "ø" ><!-- small o, slash -->
<!ENTITY ugrave "ù" ><!-- small u, grave accent -->
<!ENTITY uacute "ú" ><!-- small u, acute accent -->
<!ENTITY ucirc "û" ><!-- small u, circumflex accent -->
<!ENTITY uuml "ü" ><!-- small u, dieresis or umlaut mark -->
<!ENTITY yacute "ý" ><!-- small y, acute accent -->
<!ENTITY thorn "þ" ><!-- small thorn, Icelandic -->
<!ENTITY yuml "ÿ" ><!-- small y, dieresis or umlaut mark -->
Accounts数组有一个modification_date字段,但返回的是所有帐户。在我的测试样本中,2个具有mod日期&gt; 2016年5月15日。这种代码适用于其他领域,但不适用于以下日期:
var SomeAccounts = Array.FindAll(Accounts, x => x.modification_date > modification_date);
if (SomeAccounts == null)
{
return NotFound();
}
return Ok(JsonConvert.SerializeObject(SomeAccounts));
我做错了什么?
答案 0 :(得分:1)
确保您的数组实际上是空的
首先,Array.FindAll()
方法永远不会实际返回null
,因为如果找不到匹配项,它将返回一个空数组,因此您可能想要查看是否有任何值发现:
if (SomeAccounts.Length == 0)
{
return NotFound();
}
如果你返回的结果是一个数组(没有值),那么这是正确的(因为它以前不会因为它永远不为空而点击NotFound()
。)
审核日期
作为评论中提到的Cory,比较DateTime对象可能非常困难。您将需要确保在比较值时考虑TimeZones等任何信息。
您也可以考虑使用调试器手动检查DateTime
对象在代码中的外观(modification_date
属性和实际的modification_date
变量)。尝试在Watch窗口中比较它们,以确保比较正常。