当前位置:网站首页>About asp Net core uses a small detail of datetime date type parameter
About asp Net core uses a small detail of datetime date type parameter
2022-07-02 01:05:00 【Roman Sultan Mohammed】
1.DateTime Value type ( Basic data type ), It cannot be Null, Therefore, it cannot be used as a parameter to assign a default value
[HttpGet]
public StandResult<List<Role>> Test( DateTime start = DateTime.MinValue.,DateTime end = DateTime.MaxValue)
{
//DateTime As a parameter of the method , The default value cannot be set as above , This will report grammatical errors
........
}
2. Don't treat DateTime Parameter to judge empty , Because when you are not DateTime When a value is passed in , It will be set by default to DateTime.MinValue
[HttpGet]
public StandResult<List<Role>> QueryRoles( DateTime start,DateTime end)
{
// Don't take DateTime Carry out the empty operation , It won't be Null, If you want to use DateTime As a method parameter , Please set an initial value manually
if(start!=null)
......
if(end != null)
......
}
test :


so
In some multi condition query methods , about DateTime Parameters should be treated with a small special treatment , To avoid using without passing in DateTime The default value of
[HttpGet]
public StandResult<List<Permission>> Query_Permissions([Required]int PageIndex,[Required]int PageSize,
string name, string type, string createEmp,DateTime start,DateTime end,long Id = -1)
{
// Like this method , I use two DateTime Parameter to limit the query time ,
// According to the above situation , But it's not imported start and end date , They are all {0000-00-00....} Minimum time
// Bring in the query criteria , be time>DateTime.Minvalue&&time<DateTime.Minvalue It is a paradox of time , This leads to the direct invalidation of the condition query
if (start == DateTime.MinValue)
start = Convert.ToDateTime("1970-01-01");
if (end == DateTime.MinValue)
end = Convert.ToDateTime("9999-12-12");
List<Permission> permissions = scoper.GetTool().Queryable<Permission>()
.WhereIF(!string.IsNullOrEmpty(name), it => it.Name == name)
.WhereIF(!string.IsNullOrEmpty(type), it => it.Type == type)
.WhereIF(!string.IsNullOrEmpty(createEmp), it => it.Create_Emp == createEmp)
.WhereIF(start!=null,it=>it.Create_Time>start) // If you do not add the above initialization , When the parameter does not pass in the date type
.WhereIF(end != null, it => it.Create_Time < end) // Will directly use two identical minimum dates to judge , cause BUG
.WhereIF(Id != -1, it => it.Id == Id)
.ToPageList(PageIndex, PageSize, ref Total);
}
Last suggestion , The direct date parameter must be filled 【Required】 Writing can solve this problem perfectly ,( It must be judged that the end date is greater than the start date )
边栏推荐
- XMind思维导图
- Global and Chinese market of wireless chipsets 2022-2028: Research Report on technology, participants, trends, market size and share
- ACM教程 - 快速排序(常规 + 尾递归 + 随机基准数)
- JS -- image to base code, base to file object
- LeetCode 0241. Design priority for arithmetic expressions - DFS
- sso单点登录的实现。
- Node -- egg creates a local file access interface
- How to type spaces in latex
- Synthetic watermelon game wechat applet source code / wechat game applet source code
- 【会议资源】2022年第三届自动化科学与工程国际会议(JCASE 2022)
猜你喜欢

关于ASP.NET CORE使用DateTime日期类型参数的一个小细节
![[eight sorting ③] quick sorting (dynamic graph deduction Hoare method, digging method, front and back pointer method)](/img/c2/7ebc67e9b886e3baf3c98489bf9bce.png)
[eight sorting ③] quick sorting (dynamic graph deduction Hoare method, digging method, front and back pointer method)

【八大排序③】快速排序(动图演绎Hoare法、挖坑法、前后指针法)

BPR (Bayesian personalized sorting)

How does schedulerx help users solve the problem of distributed task scheduling?

测试人进阶技能:单元测试报告应用指南

AIX存储管理之卷组的创建(一)

SSO single sign on implementation.

【八大排序④】归并排序、不基于比较的排序(计数排序、基数排序、桶排序)

首场“移动云杯”空宣会,期待与开发者一起共创算网新世界!
随机推荐
Geek DIY open source solution sharing - digital amplitude frequency equalization power amplifier design (practical embedded electronic design works, comprehensive practice of software and hardware)
969 interlaced string
Powerful calendar wechat applet source code - support the main mode of doing more traffic
关于ASP.NET CORE使用DateTime日期类型参数的一个小细节
【八大排序②】选择排序(选择排序,堆排序)
Iclr2022 | spherenet and g-spherenet: autoregressive flow model for 3D molecular graph representation and molecular geometry generation
Global and Chinese markets for supply chain strategy and operation consulting 2022-2028: Research Report on technology, participants, trends, market size and share
LeetCode 0241. Design priority for arithmetic expressions - DFS
Cat Party (Easy Edition)
2022 safety officer-a certificate examination questions and online simulation examination
Global and Chinese markets for context and location-based services 2022-2028: Research Report on technology, participants, trends, market size and share
excel查找与引用函数
Minimize the error
Zak's latest "neural information transmission", with slides and videos
【八大排序①】插入排序(直接插入排序、希尔排序)
Friends circle community program source code sharing
The first "mobile cloud Cup" empty publicity meeting, looking forward to working with developers to create a new world of computing!
Entrepreneurship is a little risky. Read the data and do a business analysis
2022 operation of simulated examination platform for melting welding and thermal cutting work license
AIX存储管理之逻辑卷的创建及属性的查看和修改