一、通过查询条件拼接:
var query = ctx.Almmsghis.Where(t => t.TranTime.CompareTo(sFromTime) >= 0 && t.TranTime.CompareTo(sToTime) <= 0);
if (sTranTime.Trim() != "")
{
query = query.Where(t => t.TranTime.CompareTo(sTranTime) <= 0);
}
listAlmmsghis = query.OrderByDescending(t => t.TranTime).ToList();
二、将其设置为数据库该字段的默认值:
if (InTag.next_mail_group_id == "")
{
sNextMailGroupId = " ";//默认值为单个空格
}
fdcMailgroupList = ctx.Fdcmailgroup.Where(t => t.MailGroupId.CompareTo(sNextMailGroupId) >= 0 && t.Factory == sFactory).ToList();