关于LinQ的难题            string whereStr="";
            foreach (MyType part in parts)
            {
                if (whereStr != null)
                    whereStr += " || ";
                whereStr += " contact.Field<string>(\"CustoemrID\") == " + part.CustomerID + " &&  contact.Field<string>(\"otherID\")==" + part.otherID;
            }            IEnumerable<DataRow> query = 
                from contact in contactTable.AsEnumerable()
                where   // 怎么把这个Wherestr字符串拼接到这个地方? 或者有什么其他的做法不用拼接字符串?
zi

解决方案 »

  1.   

    拼!!这时候反而方便!不为linq而疯狂linq!
      

  2.   


    什么意思啊?
    怎么拼呢?这个LInQ是操作DataTable的
      

  3.   

                IEnumerable <DataRow> query = 
                    from contact in contactTable.AsEnumerable() 
                    where  // 怎么把这个Wherestr字符串拼接到这个地方? 或者有什么其他的做法不用拼接字符串? 这里的Wherestr 是一个字符串变量。
    保存着LinQ的Where条件
    怎么写到LinQ中去?
      

  4.   

    where 后面是跟表达式啊,怎么跟字符串呢?DataTable 的话,自身就有 Select 的函数吧?
      

  5.   

    把你上面那个用一个bool来存储然后再传到linq里面去!
      

  6.   


    //查询
    var xxxxxx = from w in data.News
                             where str()
                             select w;
    //return bool
    public static bool str()
            {
                return true;
            }
      

  7.   


    public static bool str()
            {
                return true;
            }
    这个Str必须得能传参数吧。
    比如:
    public static bool str(string id)
            {
                foreach ( string _id in myids)
                    if _id ==id  return true
               return false;
            }var xxxxxx = from w in data.News
                             where str(w.id)
                             select w;是这样么?
      

  8.   

    参数你根据需要自定!!嗯!那个方法只是让它返回一个bool值!!
      

  9.   

    你上次的贴子还没结!http://topic.csdn.net/u/20091023/23/196d7ecd-ce16-483d-963b-263e20685900.html看你一直在问linq的问题!自己去找些资料好好看看!
      

  10.   


    这样的查询怎样做,每一项都不固定,随机选,如果也用拼接的话,应该怎样写
    在wcf+linq实现,大家给帮忙给看看