gpt4 book ai didi

linq 像空字符串

转载 作者:行者123 更新时间:2023-12-02 06:44:14 27 4
gpt4 key购买 nike

var list = (from i in _dataContext.aspnet_Users.Include("aspnet_Membership")  where i.UserName.Contains(userName)  select i ).ToList();

如果 userName="" 那么什么都不会返回。如果空字符串然后返回所有记录,我该怎么做?

最佳答案

做:

  var list = 
(from i in _dataContext.aspnet_Users.Include("aspnet_Membership")
where string.IsNullOrEmpty(userName)
|| i.UserName.Contains(userName)
select i ).ToList();

关于linq 像空字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2670949/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com