8,497
社区成员
发帖
与我相关
我的任务
分享
select
*
from activity
where 1=1
<if test="city != null and city!=''">
and city =#{city,jdbcType=VARCHAR}
</if>
<if test="contentType != null and contentType >0">
and content_type =#{contentType,jdbcType=INTEGER}
</if>
limit #{start,jdbcType=INTEGER},#{limit,jdbcType=INTEGER}
var result = db.Activity.ToArray() // 记得使用 string.IsNullOrWhiteSpace 前需要先把数据获取到本地否则会报错
.OrderBy(o => o.property) // 确保分页的结果是正确的
.Where(w => w.status == 1)
.Where(w => !string.IsNullOrWhiteSpace(w.city))
.Where(w => (w.contentType ?? 0) > 0)
.Skip(pageCount * pageIndex).Take(pageCount)
.AsEnumerable(); // 只读列表
var query = db.Activity.Where(a=>a.Status =1);
select
*
from activity
where 1=1
<if test="city != null and city!=''">
and city =#{city,jdbcType=VARCHAR}
</if>
<if test="contentType != null and contentType >0">
and content_type =#{contentType,jdbcType=INTEGER}
</if>
and status =1
order by create_time desc
limit #{start,jdbcType=INTEGER},#{limit,jdbcType=INTEGER}
那么用linq语句写,应该怎么写啊?var query = db.Activity;
if (!string.IsNullOrWhiteSpace(city))
{
query = query.Where(a => a.City == city);
}
if (contentType > 0)
{
query = query.Where(a => a.ContentType = contentType);
}
return query.Skip(start).Take(limit).ToList();