Entity Framework 实现in查询

        private Expression<Func<Model.Current.Project, bool>> GetExpressionWhereCurrent(Model.Project obj)
        {
            var where = PredicateExtensionses.True<Model.Current.Project>();
            //单位名称
            @where = (!string.IsNullOrEmpty(obj.vcsgmc)) ? @where.And(p => p.vcsgmc.Contains(obj.vcsgmc)) : @where;
            //工程代号
            @where = !string.IsNullOrEmpty(obj.gcbm)
                         ? (obj.gcbm.IndexOf(",", StringComparison.Ordinal) > -1 && obj.gcbm.Length > 2
                                ? CurrentGcbmWhere(obj.gcbm)
                                : @where.And(p => p.gcbm == obj.gcbm))
                         : @where;
            //工程名称
            @where = (!string.IsNullOrEmpty(obj.vcgcmc)) ? @where.And(p => p.vcgcmc.Contains(obj.vcgcmc)) : @where;
            return @where;
        }
        private Expression<Func<Model.Current.Project, bool>> CurrentGcbmWhere(string gcbm)
        {
            var where = PredicateExtensionses.True<Model.Current.Project>();

            gcbm = StringFormater.StringCut(gcbm, 2, gcbm.Length - 2);
            var gcbms = gcbm.Split(',');
            @where = @where.And(p => gcbms.Contains(p.gcbm));
            return where;
        }


注意“Contains”关键字。

原文地址:https://www.cnblogs.com/blackice/p/2664177.html