本文介绍了使用System.Linq.Expressions.Expression>在枚举中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public partial class MainWindow : Window
  {
      public MainWindow()
      {
          InitializeComponent();

          DataClasses1DataContext Dc = new DataClasses1DataContext();

          // it is getting
          var x = Dc.Table4s.Where(TestTableExt.IsEqual(YesNo.Yes));

          // it produce error why ?
          var y3 = from p in Dc.Table4s where TestTableExt.IsEqual(YesNo.Yes)
                    select p;
      }
         public  enum YesNo : int
  {
      Yes = 1, No = 2
  }

  public class TestTableExt
  {

      public static System.Linq.Expressions.Expression<Func<Table4,bool>>                    IsEqual(YesNo i)
      {
          return (a => a.Num == (int?)i);
      }
  }
}



为什么我无法解决这个问题?
在此先感谢
jophy



Why this not getting help me i am in middle of a problem
Thanks in advance
jophy

推荐答案

namespace testlinqExpression
{
    /// 
    /// Interaction logic for MainWindow.xaml
    /// 
    public partial class MainWindow : Window 
    {
        public MainWindow()
        {
            InitializeComponent();

            DataClasses1DataContext Dc = new DataClasses1DataContext();

            System.Linq.Expressions.Expression> expression1 = TestTableExt.IsEqual(YesNo.Yes);
            var funtion = expression1.Compile();

            //var y3 = from p in Dc.Table4s where TestTableExt.IsEqual(YesNo.Yes).Equals(true) select p;
            var y3 = from p in Dc.Table4s where funtion(new Table4(){Num = 1}) select p;           
        }
    }

    public enum YesNo : int
    {
        Yes = 1, No = 2
    }

    public class TestTableExt
    {

        public static System.Linq.Expressions.Expression> IsEqual(YesNo i)
        {
            return (a => a.Num == (int?)i);
        }
    }
}


谢谢大家


Thanks you all


这篇关于使用System.Linq.Expressions.Expression&gt;在枚举中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 12:09